Groups | Blog | Home
all groups > flash actionscript > april 2005 >

flash actionscript : keeping the same random loaded movie


a little ant
4/12/2005 12:00:00 AM
Hi,
I have splash.swf which loads up at the beginning of my site and also plays
when other pages are loading up. (So when the user presses a button for a page,
splash.swf also appears and plays and then is told to dissappear when each page
starts to play.)
I want to load a random animation within a movie clip on splash.swf which can
be done with this simple attached code.
However, I just want a random animation at the beginning of site load, not at
each playing of splash.swf.

Master.swf (_root) loads up splash.swf but at that stage the movieclip doesn't
exist yet for me to target it.

Not sure how to tell a random animation to load into splash.swf only when the
splash.swf is run for the first time (at site start) and not at each subsequent
use. I keep thinking of the word Array - don't know why because I don't ever
use them and not sure what they are really used for. Is this doable please. My
code to at least load in a random movie (which works fine if indeed i did want
a random movie at each play of the swf) is attached. Maybe there is a way i can
randomly load an animation into a library and then just target that animation.
Please enlighted my logic. Cheers for any advice dudes/ladies.



filename = ["warp.swf", "warp2.swf", "warp3.swf"];
i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(filename[k], movieTarget);
mandingo
4/12/2005 12:00:00 AM
LOL @ thinking Array... nooooooooooooooooooooooooooooooooo not an array... if
that is what you are thinking maybe best to continue not using them.

easy though... ready ? Think variable.

//on first frame
setRandMovie = function(){
filename = ["warp.swf", "warp2.swf", "warp3.swf"];

k = Math.floor(Math.random()*filename.length);
loadMovie(filename[k], movieTarget);
myRandy = true;
}
if((typeof(myRandy) == "undefined)? setRandMovie() : stop());

the first time through, variable will be undefined and will call the
function... after that it will be a boolean and will trigger the stop() action
instead... you may need to replace that stop with something more meaningful to
your project.

I hope that helps,
cheers,

a little ant
4/12/2005 9:18:28 AM
Thanks alot. I take it this is (designed and) meant to go on my master .swf
timeline ?(my _root swf)

If yes, how do I target movieTarget from master.swf if it (or indeed
splash.swf which contains it) doesn't exist yet. (movieTarget will eventually
be on _level5.angleScreen.movieTarget) at least when the splash.swf is loaded.

Forgive any confusion on my part.

Basically my master timeline which ends at keyframe 10 and on keyframe 10
tells 2 swfs to load and one of those is splash.swf into _level5.

(With my first post - I only had it working if the code was on the first (or
so) frames of splash.swf).

I appreciate your time and Thank You.
mandingo
4/12/2005 9:37:46 AM
okay... so lets look at it as a two step process...

Step 1. Find the movie to use and store it as a useable _global.variable.

Step 2. When the movie loads, reference the variable from before...


setRandMovie = function () {
filename = ["warp.swf", "warp2.swf", "warp3.swf"];
_global.myRandImage = filename[Math.floor(Math.random() * filename.length)];
};
typeof(_global.myRandImage) == "undefined" ? setRandMovie() :
_global.myRandImage;

// on whatever movieClip loads which had your movieTarget

this.movieTarget.loadMovie(_global.myRandImage);

that should get you started... don't complicate things uneccesarily
cheers...

a little ant
4/13/2005 4:42:08 AM
Thanks mandingo,

I'm still trying to get it to work with my project.

Appreciate your expertise and Thanks alot.

mandingo
4/13/2005 5:28:17 AM
What bit are you having trouble with...

If I am understanding your question correctly... then you load splash.swf and
this is the movieClip that is looking for that random image. Is that correct?

if so, in your splash movieClip at the beginning just trace that variable and
see if it returns a value for you as you expect.

so inside splash.fla

trace(_global.myRandImage); // should bring back "warp.swf" etc.

cheers,
AddThis Social Bookmark Button