开发者

event.COMPLETE handler question

I want to dispatch a custom event when the two files are downloaded or uploade开发者_如何学运维d successfully. I use

fileRef.addEventListener(Event.COMPLETE, completeHandler);
fileBigRef.addEventListener(Event.COMPLETE, completeHandler);

to listen the complete event with only 1 handler.

function completeHandler(event:Event):void{
    var e:Event=new Event("addInfoDone");
    dispatchEvent(e);
    fileBigRef.removeEventListener(Event.COMPLETE,completeHandler);
    fileRef.removeEventListener(Event.COMPLETE,completeHandler);
}

I want the event to be dispatched only once when both of the fileRef and fileBigRef are complete transfered. Any ideas?? My brain is fry now and can't think of anything..... Thanks for the help.


For a quick and dirty solution, how about defining a counter that increments each time completeHandler is fired. Once the counter reaches the number of files you're expecting (sounds like you're expecting 2), you fire your addInfoDone event:

var fileRefCounter:Number = 0;

function completeHandler(event:Event):void{
    fileRefCounter++;
    if(fileRefCounter == 2)
    {
        // both files have downloaded; fire your custom event, or whatever
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜