PDA

View Full Version : confusion about initializing variables...HELP me plzzzz



zain
June 12th, 2002, 07:49 AM
hiyaa...

how does this work? :

I have a flash movie consisting of 3 layers each with one frame only...
(1) On the firstkeyframe of layer 1 , i have initialized a variable :

rotation=0;

(2) on the firstkeyframe of layer 2 i have a button with the following actionscript:

on(release){
rotation+=10;
}

(3) on the firstkeyframe of layer 3 i have a movieclip with the following actionscript

onClipEvent(enterFrame){
setProperty(this,_rotation,_root.rotation)
}


now the thing is all this code works fine in rotating the movie clip everytime i click the button.

what i DONT understand is when the movie is playing when it loops, how come it doesnt set the rotation variable back to 0, as in the first layer we set rotation=0;??? wont the variable be reinitialized to 0 again?

this is confusing me a bit.... why does it take the value of rotation to be the value the button set it to and not what the frame set it to?

any ideas? any help would be appreciated..

cheers
Zain

Iammontoya
June 12th, 2002, 07:57 AM
Hello, Zain.

I think the problem lies here:

Your MC on layer is looping, not the frame in layer 1.

This means that the value of _root.rotation has already been set, and unless you reload your movie, it won't be back to zero.

Solution:

A few different ways. Here are two:

in the last frame of your movie clip:

_root.rotation=0;

or, you could declare the variable in the button:

on(release){
_root.rotation=0;
}

of course this means the value is reset everytime you press the button.

or...
you could declare the variable in the MC.

Hope this helps. Good luck!

zain
June 12th, 2002, 08:01 AM
Thanks for ur reply Iammontoya,

But doesnt a flash movie automatically loop whether or not it contains any movie clips?

so if i have a flash movie with just one frame, isnt it automatically looping again and again over the same frame? ( only because it is so fast -12fps we dont notice it is actually looping?)

Iammontoya
June 12th, 2002, 08:07 AM
not quite.

if you only have one frame on the main timeline, it will not loop.

if you'd like to verify, try this simple exercise.

new movie
frame1 of the main timeline, put the following code:

rotation=0;
trace(rotation);

test your movie.

See? the value is only given once.

Now, add a frame on frame2...

test your movie.

It will loop and continue to give zeroes...

;)

zain
June 12th, 2002, 08:14 AM
yep ur right!!! thanks a lot...its cleared a lot if questions up...
thanks :)