Friday, June 12, 2009

It IS possible to do this in an AIR Application...!

A couple hours ago, I posted a question regarding loading classes from a local SWF file. I poked around a bit more thinking that the problem had something to do with the ApplicationDomain. I took another look at the LiveDocs for ApplicationDomain and tried out the example on that screen without any luck. I even commented on the LiveDoc page. I was about to go file a bug but figured I would do one more Google search on the subject. I found this a post at Actionscript.org that seemed to describe the same problem. One on the replies mentioned that he was able to work around the problem by putting a half second delay betweeen the loading of the swf and any attempt to access the classes. So, I took the ClassLoader example from the ApplicationDomain LiveDoc example and added a 500ms delay to the complete handler:

private function completeHandler(e:Event):void {
setTimeout(function(...params) {
params[0].dispatchEvent(new Event(ClassLoader.CLASS_LOADED));
}, 1000, this);
}


After that small change I was able to load the classes from the external SWF. However, this doesn't solve the FlexUnit problem because internally, FlexUnit loads the test classes using getDefinitionByName(). Even if you pass the test cases in as Classes, it gets the qualified name and then calls getDefinitionByName() resulting in the error.

1 comment:

Anonymous said...

When using external SWFs you have to register for the INIT event instead of the COMPLETE event, because the initialization of the loaded SWF is done AFTER the download is complete.