Global Variables

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)
:-\

in the first frame, just:

_global.ta1 = 0;

i think your creating a local ta1 and a _global.ta1, then setting the local ta1 to 0.

http://www.kirupa.com/developer/actionscript/as_tricks.asp
Check the global variables article.

pom :asian:

And Supra, are you also the sbeener at layer51?

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.
:-\

on(rollOver){
	if(ta1 == 0){
		_root.top.gotoAndPlay('rollstart')
	}
}

you have to put this code on the button that you want to rollOver, but it works for me.

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?

I’m so confused:(

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.

don’t use tellTarget. tellTarget and the use of “/” are old syntax from the Flash 4 days. Now Flash uses the dot-syntax method.

_root.gotoAndPlay(“whatever”)

Thanks for your help guys. I’m going to try this new information as soon as I get off work. I’ll post the results.

Still can’t get anything to happen.

I tried:
on (rollOver) {
if (_root.ta1 == 0) {
_root.top.gotoAndPlay(“rollstart”);
}
}

Also tried:
on (rollOver) {
if (_global.ta1 == 0) {
_root.top.gotoAndPlay(“rollstart”);
}
}

And
on (rollOver) {
if (ta1 == 0) {
_root.top.gotoAndPlay(“rollstart”);
}
}

Jubba you said that you had the button working I think. Could you Post that FLA so I could take a look.:frowning:

how are you defining your variable?

in the first frame of your animation you should have

_global.ta1 = 0

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.

that file worked. the MovieClip ‘top’ went to and Played “rollstart”

I’m not sure, Supra.

*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 :stuck_out_tongue: .

pom :asian:

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?

yeah, _global is mx only.

sheesh… how long did that take to work out?

ily - good point about modifying _globals.

Supra: took too long, I actually thought I asked that in one of my first posts, but I guess not.

Sin: yes, _global is only MX

Pom: :stuck_out_tongue: