I'm not sure if it's possible but if yes can someone help?
Thanks!!!
Printable View
I'm not sure if it's possible but if yes can someone help?
Thanks!!!
I've found something else:
function getArguments(arg=null)
{
//do something with arg
}
where arg can be an array of argument.
Is that cool? or not
Why would you do that?
Just do:
function (... args){
It will make an array called args from any arguments you pass it.
I would do that in case I don't want to pass any argument at all, in order to avoid the "you passed 0 arguments, was expecting 3" kind of compiling error, I guess!
I don't mean why would you want to pass x args, but why would you mess with making the array yourself. Try ... args. It's much cleaner.
oh I see, thanks a lot ! much better!
No worries.
My favorite place to use ... is for event listeners. Often times, you want a function to be triggered, but the function doesn't need to know anything about the event that triggered it. For example, if you have a function update, you may need to call it sometimes from other functions and other times with an event listener. Since update doesn't care who called it, function update(... args) will allow you to easily invoke it from sibling functions or use it as an event callback.
very nice tip! thanks! I think it actually answer a question I posted here in another thread!
Though if an event is passed to update, how do you grab the variables of the event?
You could have function update(event:Event = null) as well :)Quote:
Originally Posted by illustratedlife
args[0] would be the event. But if you are actually handling an event, you should probably be doing function undate(event:Event){ anyway. . .