从一个数组参数传递到ActionScript方法...(其余的)参数 [英] Pass arguments from an array to an Actionscript method with ...(rest) argument
问题描述
我的问题是这个问题的Flex的换位:
my question is the Flex transposition of this question :
<一个href="http://stackoverflow.com/questions/2925153/can-i-pass-an-array-as-arguments-to-a-method-with-variable-arguments-in-java">Can我传递一个数组作为参数传递给在Java可变参数的方法?
这是我在某些ActionScript code数组,我需要在数组中收录的每个对象传递到一个方法办法(...参数)
。
That is, I have an Array in some Actionscript code and i need to pass every object indexed in the array into a method method(...arguments)
.
有些code要清楚:
private function mainMethod():void{
var myArray:Array = new Array("1", "2", "3");
// Call calledMethod and give it "1", "2" and "3" as arguments
}
private function calledMethod(...arguments):void{
for each (argument:Object in arguments)
trace(argument);
}
有没有一些方法做什么意见建议?
Is there some way to do what the comment suggests?
推荐答案
这是可能的方式是遍历功能对象本身。调用适用()就可以将工作:
It's possible by going through the Function object itself. Calling apply() on it will work:
private function mainMethod():void
{
var myArray:Array = new Array("1", "2", "3");
// call calledMethod() and pass each object in myArray individually
// and not as an array
calledMethod.apply( this, myArray );
}
private function calledMethod( ... args ):void
{
trace( args.length ); // traces 3
}
有关更多信息,请访问<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Function.html#apply">http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Function.html#apply()
For more info, check out http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Function.html#apply()
这篇关于从一个数组参数传递到ActionScript方法...(其余的)参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!