Link to home
Get AccessLog in
Avatar of jrmcintosh
jrmcintosh

asked on

Getting the value of a variable from one movieclip into another movieclip

I have a master swf that holds two movieclips called menustage and mostpop. When a button is clicked in mostpop I set a value to a variable called _global.hit. When that button is clicked in mostpop I have it goto a frame in menustage. I want to be able to know what the value of _global.hit from mostpop into menustage. Currently I use this line to try and get it but when I trace it I get undefined. Any help?

trace(this._parent.mostpop._global.hit);

I traced this._parent and got level 0.

Thanks for any help.
Avatar of Zeffer
Zeffer
Flag of New Zealand image

being a global variable you can trace it with..

trace("" + _global.hit);

Z
Avatar of jrmcintosh
jrmcintosh

ASKER

I still get undefined.

Now I'm tracing it within the menustage movieclip and not the master swf but I'm guessing that doesn't matter. I am setting _global.hit to 0 on my test button in mostpop and if I trace it within there I get 0. No such luck for menustage.
try..
on the frame in menustage that you go to..

this.onEnterFrame = function(){
trace("" + _global.hit);
delete onEnterFrame;
}

Z
Nope I still get undefined...
where is the _global.hit variable being declared?
I suspect it is in mostpop on the button action..
put it on the first frame of the main timeline..which is where I have been assuming it was.. it should actually be available from anywhere in the movie as you have it..but it can be masked by using identifiers with the same names in inner scopes..which is not unlike the structure of what you're doing.

if you don't want it to have a value till you click the button..

_global.hit = "";

Z

Ok, you were correct in your thinking that I wasn't declaring it in the master swf. I did declare it in the master swf. I'm changing the value within mostpop when the button is clicked, then I want to reference the value in menustage.

After adding in your line above the value doesn't change it stays "".
ok here it is.. and i'm surprised at the code needed..considering the supposed scope of a _global var..

on the frame in menustage that you go to..

this.onEnterFrame = function(){
trace("" + _parent._global.hit);
delete onEnterFrame;
}

Z
of course this will also do it..

trace("" + _parent._global.hit);

: )
Z
I will try that, I'm sure using the parent scope will help. In mostpop the global variable is being set in a movieclip that is within mostpop so that's probably the case. I will check it this evening. This is my first major flash project and actionscript has been an interesting beast. Anyway, I'll get back to you soon. Thanks.
I have yet to get this working after being away from it for a few days. I'm really desperate here. This is the key to pretty much my whole app and I can't get it to work.

I set the _global.hit variable in the master movie on the first frame to 25.

Within the mostpop there are buttons created on the fly that hold data in them So the hierarchy with mostpop is master movie -> mostpop -> btnholder (movie that creates multiple data buttons)

When I click on one of the btnholder's I check to see which one was clicked (i.e. btnholder0, btnholder1, etc.). In those if then statements I'm trying to see if I can see that initial value of 25 but I still get blank or undefined. I've gone up to 6 _parents deep and nothing.

What do you think we could try next. Could I maybe zip up my files and post them online? I'm upping the point value on this.

Thanks.
So confused...

So I put this in the first actions frame of menustage and I get 25:
trace(_parent._global.hit);

I put the same thing in mostpop in the first actions frame and get undefined. Does it have anything to do with the fact I'm using flash remoting in mostpop???

Arrrrrgh
try to always set _global variables in the first frame of preferably main movies then they are declared early on and available through the entire scope.. if you declare them down in nested movies you may be trying to retrieve them before they have been declared.
The remoting shouldn't effect things.. it's just allowing 2 remote movies to talk..just get the paths right ;)

I still use MX6 so unless you are using that I can't look at your fla.

Z




I wish the path notion was that easy. I have tried to do the same thing in the first frame of three different movies now that load from the master. I've set my global variable to 25 in the first frame. In the first frame of all the movies loaded on the fly (menustage, ads, and mostpop) I have this code...

trace(_parent);
trace(parent._global.hit);

for menustage I get:
_level0
25

for ads I get:
_level0
25

for mostpop I get:
_level0
undefined

It makes no sense. I'm utterly frustrated. The only thing that is different about most pop is that it calls data.
in the above message trace(parent should be trace(_parent
trace(_parent) won't be doing anything.. you have to reference the variable as you do in the code under it.

try..
trace(this._parent._global.hit);

Z
Zeffer,

I think you mistook my response above. I was merely stating that I had made a typo in my post
It doesn't matter if I have this._parent or _parent, I get the same result. Two movies that show the proper global value when I trace it and one movie that pulls in data from a database that I trace the exact same way but it's value is undefined. I guess I will have to find another way to do it possibly outside of flash in a regular coldfusion page cause I can't get it to work.
ASKER CERTIFIED SOLUTION
Avatar of Zeffer
Zeffer
Flag of New Zealand image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access