Question

I am trying to load a swf written in AS2 into an AS3 swf - using Loader class and listening for Event.COMPLETE. in my onCompleteHandler function i want to add this to the stage so Im trying -

addChild(evt.currentTarget.content) 

... but I get the following error message:

Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a different part of the displayList when it has been loaded into AVM2 (AS3) content.

The AS2 swwf has a lot of code and I really dont want to have to migrate to AS3 if I can avoid it. Anybody know if this is possible or know of a differnt way to add the loaded swf to the stage. How do I then go about calling functions in the loaded swf?

Here is a code snippet -

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
var request:URLRequest = new URLRequest("testLoadSwf.swf");
loader.load(request);

function onCompleteHandler(evt:Event) {
   addChild(evt.currentTarget.content);
}

Thanks all.

Was it helpful?

Solution

The only really effective way to do this is by using LocalConnection. AS2 and AS3 can't communicate much with each other. If you still have access to the AS2 file's source, you can expose some functions with LocalConnection. There's also a neat helper class by Grant Skinner called SWFBridge that takes some of the groundwork out of doing this, it's available here: http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html

OTHER TIPS

var loader:Loader = new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); var request:URLRequest = new URLRequest("testLoadSwf.swf"); loader.load(request);

function onCompleteHandler(evt:Event) { //addChild(evt.currentTarget.content); } addChild(loader)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top