Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6113089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:49:09+00:00 2026-05-23T14:49:09+00:00

This AS3 function works for normal methods and getter methods: public function MyClassTestAPI(functionName:String, …rest):*

  • 0

This AS3 function works for normal methods and getter methods:

   public function MyClassTestAPI(functionName:String, ...rest):* {
    var value:*;            
        try {
            switch(rest.length) {
                case 0:
                    value = myObj[functionName];
                    break;
                case 1:
                    value = myObj[functionName].call(functionName, rest[0]);
                    break;
                case 2:
                    value = myObj[functionName].call(functionName, rest[0],rest[1]);
                    break;
                default:
                    throw("Cannot pass more than 2 parameters (passed " + rest.length + ")");
            }                
        } 
        return value;                
    }

Sample usage:

this.MyClassTestAPI("Foo", "arg1"); // tests function Foo(arg1:String):String
this.MyClassTestAPI("MyProperty");  // tests function get MyProperty():String
this.MyClassTestAPI("MyProperty", "new value");// tests function set MyProperty(val:String):void

The third call does not work (throws exception).
How can I make it work for setter methods as well?
Thanks!

edit:
This is a version that works, except with getter and setter that have additional parameters.
It is ok for my needs:

   public function MyClassTestAPI(functionName:String, ...rest):* {
    var value:*;            
        try {
            if (typeof(this.mediaPlayer[functionName]) == 'function') {
                switch(rest.length) {
                case 0:
                    value = myObj[functionName].call(functionName);
                    break;
                case 1:
                    value = myObj[functionName].call(functionName, rest[0]);
                    break;
                case 2:
                    value = myObj[functionName].call(functionName, rest[0],rest[1]);
                    break;
                default:
                    throw("Cannot pass more than 2 parameters (passed " + rest.length + ")");
                }                
            }  else {
                switch(rest.length) {
                case 0:
                    value = myObj[functionName];
                    break;
                case 1:
                    myObj[functionName] = rest[0];
                    break;
                default:
                    throw("Cannot pass parameter to getter or more than one parameter to setter (passed " + rest.length + ")");
               }                
            }
        } 
        return value;                
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:49:10+00:00Added an answer on May 23, 2026 at 2:49 pm

    Setter functions works as variables, so you can’t use it in this way:

        myProperty.call( "new value" );
    

    Your function for variables is pointless, because you just have to do a value assignment:

        myProperty = "new value";
    

    By the way you can include it in your function in two ways:

    1. create a third parameter what tells your function it is a function or variable
    2. create the value assignment in the catch section
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this as3 function public static function StringReplaceAll( source:String, find:String, replacement:String ) :
In AS3 you have a function on a string with this signature: function replace(pattern:*,
I have this in AS3 var myName:String = David; var result:Number = ExternalInterface.call(methodInJS, myName);
So I have something like this: var xmlStatement:String = xmlObject.node[3].@thisValue; What mystery function do
Is there a better way to use the sound channel is AS3? This works,
this works for me, but does it look correct in terms of as3 best
I'm creating library swfs in as3 this way, works like a charm (except for
I have the following as3 function below which converts normal html with links so
How to pass information in this flow: Flash(AS3) -> PHP, using XML -> Database(mysql)
I have a sketch pad made in Flash AS3 like this one here: http://henryjones.us/articles/using-the-as3-jpeg-encoder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.