PDA

View Full Version : how to detect swf has finished playing. in this context.



spiralvista
June 7th, 2009, 10:45 PM
I am using the loader class to load an external swf "cube_final.swf".
please note I am setting a movie_clip (set on stage) to alpha=0 as I want it to remain invisble until the loaded swf finishes playing. I will then set alpha = 100% .

But how to i detect that the swf has finished playing? I can detect whether its loaded (i'll place a preloader in the loading() function)

I am new to action scripting, so any pointers would be welcomed.

this.open_cube.alpha = 0

var introLoader:Loader;

function loadIntro(url:String):void {
// Set properties on my Loader object
introLoader = new Loader();
introLoader.load(new URLRequest(url));
introLoader.contentLoaderInfo.addEventListener(Pro gressEvent.PROGRESS, introLoading);
introLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, introLoaded);
}

loadIntro("cube_final.swf");

function introLoaded(e:Event):void {
// Load SWF file
this.intro_area.addChild(introLoader);
}

function introLoading(e:ProgressEvent):void {
}

JonnyR
June 8th, 2009, 04:04 AM
Hi Spiralvista,

There are a couple of way to solve this problem, the most simple would be to monitor the MoviecClip classes' currentFrame and totalFrames properties every frame, you can do that by listening for the Event.ENTER_FRAME event which is dispached by a MovieClip which is playing.



function introLoaded(e : Event) : void {
// Extract the Loaded Clip from the Loader
var loaderInfo : LoaderInfo = LoaderInfo(e.target);
var loadedClip : MovieClip = MovieClip(loaderInfo.content);

// Register EventHandler to monitor Clip playback
loadedClip.addEventListener(Event.ENTER_FRAME, this.monitorPlaybackPosition);

// Attach the Loaded MovieClip to the DisplayList.
this.intro_area.addChild(loadedClip);
}

/**
* Recieves Event.ENTER_FRAME dispatched form a MovieClip and monitors its current frame.
* When it reaches the end, this.onIntroComplete() will be called with the target MovieClip
* passed as an argument.
*/
private function monitorPlaybackPosition(event : Event) : void {
// Extract the Target Clip from the Event.
var targetClip : MovieClip = MovieClip(event.target);

// Check the currentFrame of the Target MovieClip against its totalFrames.
if (targetClip.currentFrame >= targetClip.totalFrames)
{
// We are at the end, remove the Event Listener and callback to the handler function
targetClip.removeEventListener(Event.ENTER_FRAME, this.monitorPlaybackPosition);
this.onIntroComplete(targetClip);
}
}

/**
* Called when a Loaded MovieClip completes playback.
*
* @param targetClip The MovieClip which has completed playback.
*/
private function onIntroComplete(targetClip : MovieClip) : void {
trace("MovieClip has finished playback: " + targetClip);
}


You can format code by putting it inside [ as ] [ /as ] tags on this forum.

Jonny.

spiralvista
June 8th, 2009, 07:15 AM
Hi Jonny,

I will put my code in tags next time.

I've cut and paste the code, and it works!!

Thanks very much for your time, I will now dissect your code.

spiralvista.

stevo.mit
June 23rd, 2009, 10:54 AM
Hello
Im also beginner in action script and this example doesnt work to me... Do i have to program it with classes ?
any help would be appreciated
thx

spiralvista
October 9th, 2009, 10:30 PM
Hello
Im also beginner in action script and this example doesnt work to me... Do i have to program it with classes ?
any help would be appreciated
thx


can you post your code?

Thanks

Zen08
April 27th, 2010, 09:47 AM
Hi!

I know this topic is like almost a year now but i hope somebody replies to this.

I've actually embedded this code to my project. The code works as it is,
but my problem is that when it comes to the mc.currentFrame, it doesn't follow my original fps. It looks like its loading the total frames and not actually playing the frames on the external swf according to the fps.

I hope i'm making any sense on this.

Thanks.