Apache flex 传递参数以完成事件-Adobe Flex
我使用HTTP请求下载二进制格式的图像。下载完成后,我想处理它,但我也想将图像的ID传递给完整的处理函数。。。这是怎么做到的Apache flex 传递参数以完成事件-Adobe Flex,apache-flex,actionscript,adobe,Apache Flex,Actionscript,Adobe,我使用HTTP请求下载二进制格式的图像。下载完成后,我想处理它,但我也想将图像的ID传递给完整的处理函数。。。这是怎么做到的 var loader:URLLoader = new URLLoader(); for(var i:int = 0 ; i<5; i++){ /* When completed I want to access the variable "i" */ loader.addEventListener(Event.complete, complete
var loader:URLLoader = new URLLoader();
for(var i:int = 0 ; i<5; i++){
/* When completed I want to access the variable "i" */
loader.addEventListener(Event.complete, completeHandler);
loader.load(/* a url request */);
}
private function completeHandler(event:Event):void
{
/* I want to access the passed parameter "i" so
it is the same as it was when the eventListener was added, 0,1,2,3 or 4 */
}
var-loader:URLLoader=new-URLLoader();
对于(var i:int=0;i这应该可以使用Flex的动态函数构造
下面是一个例子:
参数和处理程序:
var parameters:String = "Some parameter I want to pass";
private function loadLocalData(e:Event, parameter:String):void
{
// voila, here's your parameter
}
private function addArguments(method:Function, additionalArguments:Array):Function
{
return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}
for(var i:int = 0 ; i<5; i++){
/* When completed I want to access the variable "i" */
loader.addEventListener(Event.complete, addArguments(completeHandler, [i]));
loader.load(/* a url request */);
}
private function completeHandler(event:Event, id:int):void
{
/* I want to access the passed parameter "i" so
it is the same as it was when the eventListener was added, 0,1,2,3 or 4 */
}
示例中的用法:
var parameters:String = "Some parameter I want to pass";
private function loadLocalData(e:Event, parameter:String):void
{
// voila, here's your parameter
}
private function addArguments(method:Function, additionalArguments:Array):Function
{
return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}
for(var i:int = 0 ; i<5; i++){
/* When completed I want to access the variable "i" */
loader.addEventListener(Event.complete, addArguments(completeHandler, [i]));
loader.load(/* a url request */);
}
private function completeHandler(event:Event, id:int):void
{
/* I want to access the passed parameter "i" so
it is the same as it was when the eventListener was added, 0,1,2,3 or 4 */
}
for(var i:int=0;i这应该可以使用Flex的动态函数构造
下面是一个例子:
参数和处理程序:
var parameters:String = "Some parameter I want to pass";
private function loadLocalData(e:Event, parameter:String):void
{
// voila, here's your parameter
}
private function addArguments(method:Function, additionalArguments:Array):Function
{
return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}
for(var i:int = 0 ; i<5; i++){
/* When completed I want to access the variable "i" */
loader.addEventListener(Event.complete, addArguments(completeHandler, [i]));
loader.load(/* a url request */);
}
private function completeHandler(event:Event, id:int):void
{
/* I want to access the passed parameter "i" so
it is the same as it was when the eventListener was added, 0,1,2,3 or 4 */
}
示例中的用法:
var parameters:String = "Some parameter I want to pass";
private function loadLocalData(e:Event, parameter:String):void
{
// voila, here's your parameter
}
private function addArguments(method:Function, additionalArguments:Array):Function
{
return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}
for(var i:int = 0 ; i<5; i++){
/* When completed I want to access the variable "i" */
loader.addEventListener(Event.complete, addArguments(completeHandler, [i]));
loader.load(/* a url request */);
}
private function completeHandler(event:Event, id:int):void
{
/* I want to access the passed parameter "i" so
it is the same as it was when the eventListener was added, 0,1,2,3 or 4 */
}
for(var i:int=0;iexacly-附加方法addArguments(…)是最佳解决方案,我使用相同的方法,但它调用passParameters
public function passParameters(method:Function,additionalArguments:Array):Function
{return function(event:Event):void{
method.apply(null, [event].concat(additionalArguments));}
}
这里是对这一点的解释——它很简单而且总是有效的举例来说——附加方法addArguments(…)是最好的解决方案,我使用相同的方法,但它称为PasspParameters
public function passParameters(method:Function,additionalArguments:Array):Function
{return function(event:Event):void{
method.apply(null, [event].concat(additionalArguments));}
}
这里是对这一点的解释-它很简单而且总是有效的谢谢!所以当我在completeHandler(e:Event)中时,我如何访问“I”?@Phil,i
将作为completedhandler
函数中的id
参数传递。您可以使用id
访问它。当然,如果您愿意,您可以将id
更改为i
。:)谢谢!那么当我在completedhandler(e:Event)中时,我如何访问“i”?@Phil,i
将作为completeHandler
函数中的id
参数传递。您可以使用id
访问它。当然,如果愿意,您可以将id
更改为i
。)