0
votes

I need to load a swf file into a new swf movie. I need to check last frame to start a movie clip, etc. Everything works ok in the below code. I was using as3 and was loading also an external as3 swf movie. The problem started when I tried to load external as2 swf movies as I receive the message: TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::symbol_name to flash.display.MovieClip. Is there a way I can convert the following code to as2???? Is there another way? Please note I'm an absolute Flash beginner and I've tried my hardest to do this in as3 and now I don't see any alternative but to use as2!!! Many thanks!

var swfLoader:Loader = new Loader();
var swfFile:URLRequest = new URLRequest("file.swf");
var container:MovieClip= new MovieClip();

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadedHandler);

var currentSWF:MovieClip = new MovieClip();

swfLoader.load(swfFile);

container.addChild(swfLoader);
addChild(container); 

function swfLoadedHandler(e:Event):void {
    currentSWF = MovieClip(swfLoader.content);  
    currentSWF.addEventListener(Event.ENTER_FRAME, checkLastFrame);

    function checkLastFrame(e:Event):void { 
        if (currentSWF.currentFrame == currentSWF.totalFrames) {
            currentSWF.stop();
            bob.play();
            if (bob.currentFrame == 2) {
                bob.stop();
            }
        }    
    }
}
1

1 Answers

0
votes

There is a good answer to the question of loading AS2 content into AS3 here: Load AS2 SWF Into AS3 SWF and pass vars in URL. Basically, you're going to need to create a bridge loader in AS2 if you can't edit the AS2 content you're loading.

Edit: This (untested) code should do what you need it to in AS2:

import mx.utils.Delegate;

var mcLoader:MovieClipLoader = new MovieClipLoader();
mcLoader.onLoadComplete = Delegate.create(this, loadComplete);
var targetMC:MovieClip = createEmptyMovieClip("container",getNextHighestDepth();
mcLoader.loadClip("file.swf",targetMC);

function loadComplete(evt:Object):Void {
    targetMC.onEnterFrame = Delegate.create(this,checkFrame);
}

function checkTargetFrame(evt:Object):Void {
    if(targetMC._totalframes == targetMC._currentframe) {
        targetMC.stop();
        targetMC.onEnterFrame = null;
        bob.onEnterFrame = Delegate.create(this,checkBobFrame);
        bob.play();
    }
}

function checkBobFrame(e:Object):Void {
    if(bob._currentframe == 2) {
        bob.onEnterFrame = null;
        bob.stop();
    }
}