0

For example i have function declared in AS3.0 class:

private function log():void{
// working with arguments directly here
}

I'm calling:

log('some stuff',object,array,etc);

Then i'm calling:

log('ok');

Ofc FlashBuilder throws exception with: type 1137: Incorrect number of arguments. Expected no more than 0

How to do it?

Update

In javascript it's possible. But in AS not, isn't it's ECMA based? Why so strict...

Update

Ok nvm. Created like that atm: log(m1:*=null,m2:*=null,m3:*=null,m4:*=null,m5:*=null):void{}

2
  • why not send it as an array or object Commented Mar 4, 2012 at 17:18
  • solution as well, but kinda ugly :), each time to call log(['something']) Commented Mar 4, 2012 at 17:37

1 Answer 1

5

You can use the ... rest parameter for that:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/statements.html#..._(rest)_parameter

Example from the docs:

function average(... args) : Number{
    var sum:Number = 0;
    for (var i:uint = 0; i < args.length; i++) {
        sum += args[i];
    }
    return (sum / args.length);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.