Is there a way to dispatch event again in handler?

129 views Asked by At

For my test I need to load about 1000 files and then perform some actions with each one by one. The problem is that I can not load another file in handler, flexunit just exit after calling load(). It works when I use another loader, with previously added Event Listener(see code), but I don't think it is a good idea to add ~1000 loaders.

I had also tried to create new loader object in handler function, but I got an "Asynchronous Event Received out of Order" error when trying to add Event Listener there.

What should I do here?

[Test(async)]
public function testTest():void
{
    loader.addEventListener(Event.COMPLETE, Async.asyncHandler(this, onComplete, 10000), false, 0, true);
    loader.load(new URLRequest("file.xml"));
    //loader2.addEventListener(...);

    function onComplete(e:Event, passTroughtData:Object):void
    {
        //performing my actions with loaded file
        trace("loaded");
        //attempt 1 - test finishes after the next line
        loader.load(new URLRequest("other_file.xml"));

        //attempt 2 - causes Out of order error
        //loader = new URLLoader();
        //loader.addEventListener(Event.COMPLETE, Async.asyncHandler(this, onComplete, 10000), false, 0, true);
        //loader.load(new URLRequest("other_file.xml"));
    }
}
1

There are 1 answers

0
sinedsem On BEST ANSWER

The simplest way to do what I wanted is to create an array of loaders (extra loader for each file) and add listeners to them before calling the first load() method.