Skip to main content
Participating Frequently
October 22, 2010
Question

Async loading of test swf is never caught by listener

  • October 22, 2010
  • 3 replies
  • 2503 views

Hi all,

I'm really struggling getting a testing structure in place. I need to test a sub-swf which gets loaded into a range of main applications and its methods are then invoked. Therefore, I want to setup a test initially to load in that sub-swf (before calling its functions).

However, despite Firebug revealing that the swf in question was called ok (200 return) the timeout function always eventually is invoked.

Please can someone tell me what I'm doing wrong as I've been struggling with this for over a week.

Code roughly copy-and-pasted (no errors when I run the original)...

public class loadSWFTester
{

import flash.display.Loader;

import flash.display.LoaderInfo;
import flash.events.*;

import org.flexunit.asserts.*;
import org.flexunit.async.Async;


private var _loader:Loader;
private var _request:URLRequest;

[Before(async)]
public function setUp():void
{
_loader = new Loader();
_request = new URLRequest("http://example.com/my.swf");

[Test(async, description="Swf load example")]
public function loadSwf():void
{

_loader.addEventListener(Event.COMPLETE, Async.asyncHandler(this, verifySwfLoad, 10000, null, handleTimeout));

_loader.load(_request);

}

private function verifySwfLoad(event:Event, passThroughData:Object):void
{
trace("[verifySwfLoad");

}

private function handleTimeout(event:Event):void
{
fail(" testLoad did not execute: "+event);

}

}

This topic has been closed for replies.

3 replies

Participating Frequently
October 24, 2010

If I specify a non-existant URL then I get this error:

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

...so the previous URLs I've been specifying must've been verified by the Flash player before failing in some respect somewhere else.

No event listeners seem to pick up on anything. I've tried adding a few extra (not in the example link I supplied previously yet) but the timeout function is the one which is always hit.

_loader.addEventListener(Event.INIT, Async.asyncHandler(this, initHandler, 10000, null, handleTimeout));
_loader.addEventListener(IOErrorEvent.IO_ERROR, Async.asyncHandler(this, onIoError, 10000, null, handleTimeout));

I've tried moving these listeners up in the [Before] block too with similar results.

Participating Frequently
October 24, 2010

The events you are listening for are not dispatched from the Loader

instance, but from its contentLoaderInfo property. If you update your

test as follows it should start working:

[Test(async, description="Async Success Example")]

public function loadSwf():void

{

_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,

Async.asyncHandler(this, verifySwfLoad, 10000, null, handleTimeout));

loader.load(request);

}

-- Daniel R. <danielr@neophi.com>

Participating Frequently
October 24, 2010

Thanks a lot Daniel!

I am still trying to work out a couple of things however, namely why Firebug doesn't reveal it's trying to load the .swf if loaded in locally (it appears when you specify a remote URL), and why can't I add more than one listener than the Event.COMPLETE...it results in the test failing when subsequently run:

Error: Asynchronous Event Received out of Order

Adding the eventListeners in the [Before] function doesn't help. Does FlexUnit4 support more than one eventListener being applied at a time?

Participating Frequently
October 22, 2010

Sample now here (and thanks once again): https://dl.dropbox.com/u/877754/flexunittests.zip

Participating Frequently
October 22, 2010

Can you provide a project that shows the issue?

1) Are you sure it actually occurs within the 10 seconds you are allowing?

2) Did you check to see if you are getting any of the other events that the loader dispatches? You are checking for complete... what if you are getting a security error or other such issue in Flash?

Mike

Participating Frequently
October 22, 2010

Thanks so much for answering; will try and put together an example project shortly. In the meantime I'll answer the questions...

1. Yes. I've tried referencing the file both locally and remotely (i.e. stuck the .swf on a server). Firebug displays a 200 return and accurately reflects how large the .swf is, so it's being called alright

2. Tried IO_ERROR at one point too but that didn't work either I don't think

Regarding loading the file in locally; what should be the correct load path from where the test is running from? My .swf(s) end up in a standard setup of bin-debug or bin-release but I've been trying to target using just the name of the .swf when running locally (i.e. no directory or subdir path). Should that be correct? When I try locally however the .swf I'm trying to load doesn't even appear in Firebug, so I'm guessing not...

Participating Frequently
October 22, 2010

Be sure to look at more than just IO_ERROR. There are half a dozen events emitted by that Loader. Firebug seeing a 200 is great, but it means little. That just means the browser was able to get the file. Whether flash player loads it correct... and is able to use it... is the work of the Loader.

So, you could see a 200, but Flash could be throwing a security error

Mike