Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : detecting external swf frame


stealth123
3/18/2006 10:40:00 PM
I am using Flash MX 2004 and am trying to load external swf files into a main
file that detects when it is at the end of the first swf and moves on to the
next. I have attached my code below, I can't figure out how to reference the
swf that is loaded in the container_mc file instead of referencing the
container_mc file itself.

I can't put any code in the swf file being loaded because they are originally
exported from Captivate, so I have to treat them strictly as swf files.

Any help would be greatly appreciated.
Thank you.

//stop the main timeline
stop();

//load swf into first movie clip
container_mc.loadMovie("circle.swf");

if(container_mc._currentFrame == container_mc._totalFrames) {
gotoAndPlay(2);
}
kglad
3/18/2006 10:46:19 PM
you have 2 problems.

1. flash is (usually and in this situation) picky about using the correct
case.

2. your code needs to be looping so flash can continually check if
container_mc._currentframe==container_mc._totalframes.
philip73
4/6/2006 12:45:41 AM
This works for me. I'm using the Loader component, but you can use a
plain-jane empty movieclip, too.

- philip



import mx.controls.Loader;

createClassObject(Loader, "media", 4);
media.contentPath = "demo.swf";
media.move (0, 0);
media.setSize (550, 400);
media._lockroot = true;

//Code for automatically unloading swf after it has finished playing

//Assign a variable to the content.
var contentSwf = media.content;

//Create a function for the listener
var loadtest:Object = new Object();
loadtest.complete = function(){

//---watch for end of loaded SWF ---
contentSwf.onEnterFrame = function() {

var current = contentSwf._currentframe;
var total = contentSwf._totalframes;

trace("current frame: " +current +"\ntotal frames: " +total);

if (current == total) {
//do something
delete this.onEnterFrame;
trace("SWF has ended.")
}
}
}

media.addEventListener("complete", loadtest);
erik_dl
5/12/2006 12:00:00 AM
Do you have an example how to use the MC in this case?

I try it with:

swf_mc.LoadMovie("test.swf");

var contentSwf = swf_mc.content;

contentSwf.onEnterFrame = function() {

var current = contentSwf._currentframe;
var total = contentSwf._totalframes;

trace("current frame: " +current +"\ntotal frames: " +total);

if (current == total) {
delete this.onEnterFrame;
trace("SWF has ended.")
}
}

but the current frame isn't displayed.
AddThis Social Bookmark Button