PDA

View Full Version : MovieClip and external swf removal


CMYMatt
02-10-2010, 01:47 AM
So, I have a video player here.
And basically you click a button and Flash loads a MovieClip from the library, then the MovieClip tweens scaleX from 0 to 1, loads an external swf (which in this case is a video player that plays a video when its launched), and adds it to the stage.
Now all that works just fine and dandy.

But when I try to remove the bugger by using a close button that removes the mc and its contents the audio from the video is still playing in the background.

Try it yourself : http://cmyokay.com/comps/kashmere/video.html.

Here is the code from the main FLA that is opening things up.


import flash.display.SimpleButton;
import gs.*;
import gs.easing.*;
//

//----- VIDEO ------\\
//disable mouse children for non-clickables
tv.staticScreen.mouseChildren = false;

//video button listeners and functions
tv.menu_cont.letters_btn.buttonMode = true;
tv.menu_cont.letters_btn.useHandCursor = true;

//listeners and functions
var lettersLoader:Loader = new Loader;
//var lettersVideo:MovieClip;

//create instance of vidCont and close button
var vidCont:MovieClip = new vidContaner;

tv.menu_cont.letters_btn.addEventListener(MouseEve nt.CLICK, getVideo);

function getVideo(me:MouseEvent):void {
//make vid cont
addChild(vidCont);
vidCont.x = 653;
vidCont.y = 570;
vidCont.scaleX = 0;
vidCont.scaleY = 0;

//add listener to button
vidCont.closeVideo_btn.addEventListener(MouseEvent .CLICK, closeVideo);

//twee in vid cont
TweenLite.to(vidCont, .5, {scaleX:1, scaleY:1, ease:Strong.easeInOut, onComplete:loadLettersVideo});
}

function closeVideo(me:MouseEvent):void {
//make vid cont
TweenLite.to(tv.vidCont, .5, {scaleX:0, scaleY:0, ease:Strong.easeInOut});

//bring back tv menu
TweenLite.to(tv.menu_cont, .8, {alpha:1, delay:1.5, ease:Strong.easeOut});

vidCont.closeVideo_btn.removeEventListener(MouseEv ent.CLICK, closeVideo);

//vidCont.removeChild(closeVideo_btn);
var v = vidCont;
while (v.numChildren) {
v.removeChildAt(0);
}

}

function loadLettersVideo():void {
//fade out menu_cont
TweenLite.to(tv.menu_cont, .8, {alpha:0, ease:Strong.easeOut});
//load video
lettersLoader.contentLoaderInfo.addEventListener(E vent.COMPLETE, gogoLettersVideo);
lettersLoader.contentLoaderInfo.addEventListener(P rogressEvent.PROGRESS, onProgress);
lettersLoader.load(new URLRequest("lettersvideo.swf"));
}

function onProgress(pe:ProgressEvent):void {
var loaded:Number = pe.bytesLoaded;
var total:Number = pe.bytesTotal;
var pct:Number = loaded/total;
vidCont.load_txt.cacheAsBitmap = true;
vidCont.load_txt.text = Math.floor(pct * 100) + "%";
}

function gogoLettersVideo(e:Event):void {
vidCont.load_txt.alpha = 0;
vidCont.load_txt.visible = false;
vidCont.addChild(lettersLoader);
lettersLoader.x = -428;
lettersLoader.y = -300;
//lettersVideo = MovieClip(lettersLoader);
}



Any help would be grand; I'm a bit lost.
I know Flash 9 has issues removing externally loaded swfs but Im sure one of you rather intelligent people out there can help a brotha out.

Cheers!

RogerClark
02-10-2010, 07:58 AM
There are a couple of things you can try.

If you loaded the video swf using the Loader class, you can call the unload() method on the instance of the loader.

However its a bit messy just unloading it while the video is playing and hope the garbage collector sorts things out straight away.

If you have the source for the video playback swf, it would be best if you could sent a message to the swf to tell it to stop the video playback, and then do its own internal housekeeping, before you actually unloaded it.

CMYMatt
02-10-2010, 03:23 PM
Hey RogerClark, thanks for the tips.
how would you suggest I go about sending a message to the swf?

henke37
02-10-2010, 05:25 PM
I would try simply calling a method of the main timeline for it.

CMYMatt
02-25-2010, 07:36 AM
Thanks for all the help guys - I finally got it.

What I ended up doing was using the LocalConnection (which I believe was what RogerClark was hinting at) to trigger a function inside the loaded swf video to stop the video and close all connections. After all that happens the swf is unloaded in the main swf so that it can be reloaded without error.

Works like a charm!

Thanks again!

I can know say that I can control streaming content!