A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: slight concern about the way MX handles variables

  1. #1
    Running Plodding & Limping SpockBert's Avatar
    Join Date
    Jun 2002
    Location
    London
    Posts
    593

    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?

  2. #2
    Retired Mod aversion's Avatar
    Join Date
    Jun 2000
    Location
    insomnia
    Posts
    7,917
    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.

  3. #3
    Running Plodding & Limping SpockBert's Avatar
    Join Date
    Jun 2002
    Location
    London
    Posts
    593
    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

  4. #4
    Retired Mod aversion's Avatar
    Join Date
    Jun 2000
    Location
    insomnia
    Posts
    7,917
    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
    }

  5. #5
    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.

  6. #6
    Retired Mod aversion's Avatar
    Join Date
    Jun 2000
    Location
    insomnia
    Posts
    7,917
    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


  7. #7
    Running Plodding & Limping SpockBert's Avatar
    Join Date
    Jun 2002
    Location
    London
    Posts
    593
    ah cheers for the link

    cleared a few things up for me

  8. #8
    Aallow! what's owll this then? iqevil's Avatar
    Join Date
    Aug 2001
    Location
    London Town
    Posts
    141
    Didnt get to see Fredi Kanoute's goal but heard it was "fantastic"... That would do for me!

  9. #9
    curmudgeon swampy's Avatar
    Join Date
    Jan 2001
    Location
    [wakey]
    Posts
    2,775
    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..."

  10. #10
    Not PWD ViRGo_RK's Avatar
    Join Date
    May 2001
    Posts
    1,799
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center