I have been trying to set up and use global variables
and I just can’t see to get it to work. I have a
scene with 2 layers
in the first frame of the first layer I have this
action script:
var ta1;
_global.ta1;
ta1 = 0;
On the second layer I have an MC called “tabtop” with
the instance name “top”. Inside this movie clip I have
I have a MC named “tab1motion” with an inscatnce name
of “tab1”. I have this MC tweened to move in and out a
certain distance on the stage. In side of the “tab1motion”
MC I have my graphic and a button. The button
has an action script of:
on (rollOver) {
if (ta1 == 0) {
tellTarget ("/top") {
gotoAndPlay (“rollstart”);
}
}
}
If I comment out the if statment the animation works
but if I try to use the variable if dosn’t do a thing.
I’am using the variable because I would like to have
4 actions on this button. A rollOver, rollOut, and 2
differnt onRelease actions using the “if statments”
and the global variable. I know I’am probably way off
with the code but any help anyone can give would be
great.(p.s. I’m using flash 5)
:-\
So if I want to manipulate the global variable I have to put _global. in fornt of it.
on (rollOver) {
if (_global.ta1 == 0) {
tellTarget ("/top") {
gotoAndPlay (“rollstart”);
}
}
}
I tried that but still my action script does nothing when I rollOver. I have attached the FLA if any one would like to take a look at it and see what the can figure out with it.
:-\
How come tellTarget dosen’t work? Isn’t the same? Does the “If” statment not work with a tellTarget becasue the tellTarget works until the “If” is added?
to set a global variable, you must use _global, thereafter you don’t need to use _global (that’s kinda the point).
however, there is (as always) an exception. flash will still look in a local namespace first, so if you’ve created a variable by the same in the local space, you’ll have to use _global if you want the global variable because otherwise flash will default to the local one.
make sense?
ily - yup. i guess there can’t be too many sbeeners out there, can there? those prototypes were written ages ago while i was working on the depth sorting for that 3d app.
the regular sort is pretty useless, but i can’t delete it. the sort a multi dimensional array by a give index is much handier. it’s faster using utilising the built in sort() method, but mine will sort 5 as lower than 15, where sort() just uses the first character. can be handy.
Yep thats what I have. I have even tried putting the global variable in the MC action with a onload event still nothing. Here is the current FLA take a look if you want to check it out.
*Originally posted by sbeener *
**to set a global variable, you must use _global, thereafter you don’t need to use _global (that’s kinda the point).
however, there is (as always) an exception. flash will still look in a local namespace first, so if you’ve created a variable by the same in the local space, you’ll have to use _global if you want the global variable because otherwise flash will default to the local one.
make sense?
**
You don’t have to use _global to access the variable, but if you want to modify it, you have to use it. Otherwise Flash will create a new variable in the local space that will hide the global variable. At least, that’s what my tests showed me.
And about the prototypes, I’ll try and read them when I get the chance .
Jubba that exact file that I posted worked for you? If it works for you without changing it is there a reason you can think of why it won’t run for me? I’m using that exact FLA and when I rollOver the button nothing happens. I’m running flash 5 will this script only work in MX?