-
Running Plodding & Limping
slight concern about the way MX handles variables
maybe i should post this in the technical forums but..well its not really a problem I'm stuck on, just curious to see what other people think.
Only made the switch to MX from 5 a little while back and there seems to be a different way of handling the variables, even on really really simple things.
for example if say I have a movieclip on the main stage called say "dog" and I want to use a variable called i dunno say "whatever" to change the _xscale of that clip. On a frame in the main timeline I would have something like this:
whatever = 20;
tellTarget ("/dog") {
_xscale = whatever;
}
thats fine for Flash5 but doesn't work on MX to get it to work in MX I'd have to change it to:
whatever = 20;
tellTarget ("/dog") {
_xscale = _root.whatever;
}
now I know it doesn't seem like a big deal but surely the fact that i declared the variable "whatever" while on the main timeline it knows that its on the root?
so if i was to have the above code inside a couple of movieclips, i'd have to have:
whatever = 20;
tellTarget ("/dog") {
_xscale = _root.myclip1.myclip2.whatever;
}
which i thinks nuts..why've they changed it? Just seems like now I'll have to add lots of extra notation that wasn't necessary before with Flash5.
oh and did anyone happen to see Fredi Kanoute's wondergoal?
-
Retired Mod
you should really update your syntax to something like
Code:
whatever = 20
mc._xscale = whatever
which works in exactly the same way
the problem with the references you have there is that they changed the event model in MX and for functions the object reference is to the caller.
-
Running Plodding & Limping
yeah I would have used that notation (i know the old tell target is old hat)but I've got loads of movieclips to muck about with, 20 in fact. I've (maybe a mistake...thinking about it now) labelled the instances "1,2,3....20" but if I try to reference instance "20" and go:
_root.20._xscale = whatever
it doesn't like the fact that the instance name is a number, if I use TellTarget it doesn't seem to mind.
ak ok...sorted it now
if I put the instance name as "m20" instead of "20" it works just like you said.
Oh well thats a lesson learned tonight...better instance naming convention needed for MX
-
Retired Mod
yah you should never name your variables like that, but you can get around that by cheating a bit and using the array style reference to the timeline...
Code:
whatever = 20
_root["20"]._xscale = whatever
will work. I assume because flash will evaluate it as a string.
it's a great way to make loops for setting properties. So if you name yours m1, m2, etc now you can say
Code:
whatever = 20
for(n=0;n<something;n++) {
_root["m"+n]._xscale = whatever
}
-
No!
the problem you were having was scope.
you declare a variable x in the _root timeline, then go to movie named dog and say 'use x', but dog knows nothing about x. Since _root know about x you tell dog to use _root.x. Dog then assumes that _root knows about x so everything is fine.
-
Retired Mod
yah that's the word I was trying to think of with "function object reference"
they changed the scope of functions between 5 and mx, check this out, might help you adjust, http://www.kirupa.com/developer/acti...icks/scope.htm
-
Running Plodding & Limping
ah cheers for the link
cleared a few things up for me
-
Aallow! what's owll this then?
Didnt get to see Fredi Kanoute's goal but heard it was "fantastic"... That would do for me!
-
curmudgeon
my main gripe is that variable names are now case sensitive and all my sloppily coded old files have to be rewritten.
"They're very much like scruffy pigs to look at, and they've got big, knobbly warts and lumps all over their long, hairy faces. They are very, very ugly indeed..."
-
Not PWD
The Techie way = Cut first, measure later, fix it when you can.
PAlexC: That's just Chuck Norris's way of saying sometimes corn needs to lay the heck down.
Gerbick: America. Stabbing suckers since Vespucci left.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|