Groups | Blog | Home
all groups > flash actionscript > february 2007 >

flash actionscript : flash SWF rotator - how do i play swf's in order


downsound
2/6/2007 7:10:46 PM
I have a simple task thats taking way too long.

I have a few swf movies that are going to play on a billboard like stage, one
after another, for example, this application could be an swf ad rotator....

questions:
1.) how do i know when the first swf is over?
I guess i could watch the frames, but isn't there a simple way (in
actionscript) to play say a list of urls like

/*
http://mysite.com/1.swf
http://mysite.com/2.swf
http://mysite.com/3.swf
http://mysite.com/4.swf
*/
//ok so put them in an array,

var myArray:Array = new Array();
myArray.push("http://mysite.com/1.swf");
myArray.push("http://mysite.com/2.swf");
myArray.push("http://mysite.com/3.swf");
myArray.push("http://mysite.com/4.swf");

trace(myArray); // one,two,three, four

//now why cant i load the first one

var mc:MovieClip = this.createEmptyMovieClip("mc", 2);
var billboard:MovieClip = mc.createEmptyMovieClip("billboard",
mc.getNextHighestDepth());
billboard.loadMovie(myArray[0]); // first swf
billboard._x = 0;
billboard._y = 0;

/* so far so good, except the first swf loops
why can't i just do this logically

load the first movie
read the length of frames of the loaded movie
say half way thru the playing of the first movie, load the next
when the first movie is finished, play the next

*/

the key is how do I check to see if the first swf is finished?
use a frame watcher function?


any help would be way cool

rick oneil
kingston, jamaica


kglad
2/6/2007 8:58:14 PM
either start a loop that continually checks the _currentframe of the first swf,
define a watch() function to check the _current of the first swf or define a
variable or call a function on the last frame of your first swf.
downsound
2/7/2007 4:11:32 PM
so in writing the loop to check the total frames and current frame, i'm getting
infor for the parent movie, not the loaded swf movie

ie.
/*creating the movieClip like this


var mc:MovieClip = this.createEmptyMovieClip("mc", 2);
var billboard:MovieClip = mc.createEmptyMovieClip("billboard",
mc.getNextHighestDepth());
billboard.loadMovie(myArray[0]); // first swf
billboard._x = 0;
billboard._y = 0;

/* then to get the properties of that movie i'm doing this

trace ("billboard._totalframes : " + billboard._totalframes);
trace ("billboard._totalframes : " + billboard._totalframes);

but in the output window i get the properties of the parent (calling) movie....



kglad
2/7/2007 7:55:58 PM
i'm not sure why your duplicating that trace statement but that will display
the _totalframes of you external swf WHEN loading is initiated.

you should use preloader code or the onLoadStart() method of the
moviecliploader class' listener.
downsound
2/8/2007 5:15:29 PM
that was typo, i'm a bit farther...

in the code , the output window shows the first billboard swf frames ticking
down to the end.

questions:

1.) the second movie plays but i cant seem to test the current frame?
2.) how can i loop in a different way, at will say in a finction to test the
movie location?

there must be an easier way to do the following:

obtain the url list, for now I'll just populate the array,
eventually code a recordset to feed the urls dynamically.

load and play the frst swf from frame 2 (frame i is the stopped state in the
loaded swf's)

while the first is playing, start loading the second, in another mc
when the first swf is finished (ie. _currentframe == _totalframes)
play the next same way and repeat untill the last swf in the array
then loop the playback to the top ( ie if say a loop parameter is true).
to play the entire list again.....




function initBillboard(url:String):Boolean {
var myVariable:Boolean;
trace (url);
billboard.unload;
billboard.loadMovie(url);
billboard._y = 0;
billboard._x = 0;
billboard._xscale = 100;
billboard._yscale = 100;
return (true);
}

var myArray:Array = new Array();
myArray.push("http://site.com/swf1.swf");
myArray.push("http://site.com/swf2.swf");
myArray.push("http://site.com/swf3.swf");
myArray.push("http://site.com/swf4.swf");



initBillboard(myArray[0]);
_root.onEnterFrame = function() {
trace("current frame : " + billboard._currentframe);
trace("movie length : " + billboard._totalframes);
if (billboard._currentframe == 1) {
billboard.gotoAndPlay(2);
frameLength = billboard._totalframes;
trace("frameLength " + frameLength);
}
if (billboard._currentframe == frameLength) {
trace("first done");
initBillboard(myArray[1]);
trace("2-current frame : " + billboard._currentframe);
trace("2-movie length : " + billboard._totalframes);
if (billboard._currentframe == 1) {
billboard.gotoAndPlay(2);
frameLength = billboard._totalframes;
trace("frameLength " + frameLength);
}
delete this.onEnterFrame;
} end if
}; /* end f
stop();
z3b3dy
2/15/2007 11:16:25 PM
AddThis Social Bookmark Button