views:

321

answers:

1

Hi

I'm trying to get an external swf to load when the flv content of another external swf finishes playing.

I've only been using actiosncript 3 for about a week and I've got to this point from tutorials, so my knowledge is limited.

This is what I've got so far:

Code for External swf (with flv content):

import fl.video.FLVPlayback;

import fl.video.VideoEvent;



motionClip.playPauseButton = player;
motionClip.seekBar = seeker;




motionClip.addEventListener(VideoEvent.COMPLETE, goNext);



function goNext(e:VideoEvent):void {

nextFrame();

}

And this is the code for the main file:

var Xpos:Number=110;
var Ypos:Number=110;
var swf_MC:MovieClip = new MovieClip();
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest("arch_reel.swf");

addChild (swf_MC);
swf_MC.x=Xpos
swf_MC.y=Ypos

loader.load(defaultSWF);
swf_MC.addChild(loader);
//Btns Universal Function
function btnClick(event:MouseEvent):void{
SoundMixer.stopAll();
    swf_MC.removeChild(loader);

    var newSWFRequest:URLRequest = new URLRequest("motion.swf");
    loader.load(newSWFRequest);
    swf_MC.addChild(loader);


}
function returnSWF(event:Event):void{
    swf_MC.removeChild(loader);
    loader.load(defaultSWF);
    swf_MC.addChild(loader);
}
//Btn Listeners
motion.addEventListener(MouseEvent.CLICK,btnClick);

swf_MC.addEventListener(swf_MC.motionClip.Event.COMPLETE,swf_MC.motionClip.eventClip, returnSWF);

I'm starting to get an understanding of how all of this works, but it's all to new to me at the moment, so I'm sure I've approached it from the wrong angle.

Any help would be fantastic, as I've been trying at this for a few days now.

Thanks

A: 

There's probably several issues here but one quite obvious is that you don't seem to add the listener at the right place.

If you have A.swf and want to listent to the loaded B.swf's timeline you need to add the listener to directly to the timeline and not to any container or loader unless you 'bubble' the event up.

A.swf

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSWFLoaded);
loader.load( new URLRequest("B.swf"))

function onSWFLoaded(e:Event):void
{
    var loaderInfo:LoaderInfo = e.target as LoaderInfo;

    // cleanup the expired event listener
    loaderInfo.removeEventListener(Event.COMPLETE, onSWFLoaded);

    // since the SWF is now loaded you can add a listener to it's timeline ('content')
    loaderInfo.content.addEventListener("VideoComplete", onVideoComplete);

function onVideoComplete(e:Event):void
{
    // do something here ; )
}

B.swf

   // ... your code ...

    video.addEventListener(VideoEvent.COMPLETE, onVideoComplete);

    function onVideoComplete(e:Event):void
    {
         // Notifies A.swf that the playback is finished ("VideoComplete" is just custom event, up to you to improve ...)
         dispatchEvent(new Event("VideoComplete"));
    }
Theo.T
Awesome!!!All done and it works perfectly.Thanks so much Theo. It's been really frustrating as I've started to grasp how actionscript 3 communicates but don't have enough background knowledge to execute it properly.Thanks again!
wdense51
Great ; ) accepted then ? (my tiny reward)
Theo.T