Groups | Blog | Home
all groups > flash actionscript > november 2004 >

flash actionscript : actionscript in movie


yjeanp
11/28/2004 10:07:38 PM
:confused;
Can someone help me out here?

I created a flash movie and want to run a random function everytime the movie
refresh. currently, I have the actionscript at frame 1 of the movie on its own
layer. It seems to run when I test the movie w/i the application, but when I
run this movie via the web(from server), it doesn't work properly. I'm not
sure if this is where I put the actionscript. Please advise.

The other problem is that at frame 5, I give the user a button to return to
frame 1. I want the user to go back to frame 1 without rerun the random
script. However, that's not possible because of where I put the script. I
would like the user to be able to return to frame 1 w/o running this random
script.

Thanks

NSurveyor
11/28/2004 10:20:02 PM
To stop the script running after returning to frame 1:
===============================
//PUT THIS SCRIPT ON FRAME ONE
if(firsttime != false){
firsttime == false;
//PUT CODE FOR RANDOM SCRIPT HERE
}
==============================
Could you post the code you are using, so I may be able to figure out why it
isn't working on the web.

NSurveyor
11/28/2004 10:21:37 PM
Sorry I messed up:
===============================
//PUT THIS SCRIPT ON FRAME ONE
if(firsttime != false){
firsttime = false;
//PUT CODE FOR RANDOM SCRIPT HERE
}
yjeanp
11/28/2004 11:07:58 PM
Thank u so much!

Here is the code w/ your suggestion:

if(firsttime != false){
firsttime = false;
myNum1 = Math.random()*4 + 1;
myNum = Math.round(myNum1);
trace(myNum);
gotoAndStop(myNum);
}


NSurveyor
11/28/2004 11:58:26 PM
yjeanp
11/29/2004 12:10:12 AM
on the web, their appear to be a frame 1 that is not my frame 1. I don't know when this frame is coming from. and the random function doesn't work here.

do u know why?
NSurveyor
11/29/2004 12:46:00 AM
Sorry about that, you can do something like this:
stop();
this.onEnterFrame = function(){
if (_framesloaded == _totalframes) {
if(firsttime != false){
firsttime = false;
myNum1 = Math.random()*4 + 1;
myNum = Math.round(myNum1);
trace(myNum);
gotoAndStop(myNum);
}
}
}
yjeanp
11/29/2004 12:53:28 AM
Jeckyl
11/29/2004 11:16:38 AM
[quoted text, click to view]

That code won't work .. it the frame is not yet loaded.

You NEED (not just should have) a preloader so you ensure that the frame(s)
you can be jumping to with the gotoAndStop will actually be loaded ...
otherwise the gotoAndStop is ignored (or may go somewhere else).

Always be VERY wary of forward jumps (to a frame later in the movie). If it
is at all possible that hte frame has not yet loaded, you need to either
prload it, or only enable you code whne the frames are loaded

Even for a cached SWF file, the player will only load at most the first 8K
of the movie by the first frame.

Jeckyl

AddThis Social Bookmark Button