A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: instance names inside of variables

  1. #1
    Member
    Join Date
    Sep 2000
    Location
    Toronto
    Posts
    46
    Let's say I have the name of an instance called 'themovie1' dumped into a vriable called 'select'.

    If I had a button at the top that would change the scale of any movieclip on the stage according the name of the variable, how would I reference it?

    I have tried a few methods, but they don't work..

    _root._name.select._yscale

    and

    _root.select._yscale

    Please help! I know this is probably very simple.. just like me.

  2. #2
    Member
    Join Date
    Aug 2000
    Posts
    44
    eval("_root." add select add "._yscale")

  3. #3
    Member
    Join Date
    Sep 2000
    Location
    Toronto
    Posts
    46
    Originally posted by frames
    eval("_root." add select add "._yscale")
    Thanks! That sounds a little closer to what I'm looking for. But I guess I should have shown the whole formula for what I'm trying to do, because I still can't get it to scale the instances properly. Should I have those '+1' and '= 150' arguments on the inside or the outside of the brackets?

    onClipEvent (enterFrame) {
    if (drag == true) {
    eval("_root." add select add "._yscale") = eval("_root." add select add "._yscale")+1;
    eval("_root." add select add "._xscale") = eval("_root." add select add "._xscale")+1;
    }
    if (eval("_root." add select add "._yscale") > 150) {
    eval("_root." add select add "._yscale") = 150;
    eval("_root." add select add "._xscale") = 150;
    }
    }
    onClipEvent (load) {
    }

  4. #4
    Senior Member
    Join Date
    Dec 2000
    Posts
    248
    or

    _root[select]._yscale;


    martin.

  5. #5
    Senior Member
    Join Date
    Dec 2000
    Posts
    248
    to clean it up a bit, use a couple more variables to refer to the x and yscale properties.

    onClipEvent (enterFrame) {

    // get the current values
    var xs = _root[select]._yscale;
    var ys = _root[select]._xscale;

    // same as if drag == true
    if (drag) {
    // same as ys = ys + 1;
    ys++;
    xs++;
    }
    if (ys > 150) {
    ys = 150;
    xs = 150;
    }

    // update the clip using the modified values
    _root[select]._yscale = ys;
    _root[select]._xscale = xs;
    }

    The advantage of putting the values into the variables is that if / when you start adding more code to check and modify the scale, you can modify the variables first, check they are in range, and then put them back into the properties.

    I hope this makes sense.

    martin.

  6. #6
    Member
    Join Date
    Sep 2000
    Location
    Toronto
    Posts
    46
    I've noticed something else now.. while looking at the debug boxes, I saw this:

    Movie Clip: Frame=2 Target="_level0.themovie1"
    Variable _level0.select = "themovie1"

    I tried accessing them again using what you guys gave me, but replacing _root with _level0

    It still doesn't work!

  7. #7
    Junior Member
    Join Date
    Jan 2001
    Posts
    10
    I had the same issue as you and someone offered this, and it works well:

    animal=pig;
    _root.animal.gotoAndPlay(2);

    that will gotoAndPlay frame 2 of movieclip _root.pig...
    This is 100% correct, the problem lies somewhere else.

  8. #8
    Junior Member
    Join Date
    Jan 2001
    Posts
    10
    Forgive me if I'm a tad obvious (i'm trying to learn this stuff too!)

    I believe the reason why using:
    eval("_root." add select add "._yscale")

    isn't working for ya is that select is *not* a string, perhaps?

    if select was a string you would have to assign it like so:
    select= "movieclip1";

    I am unsure which way you need to assign it to refer to the clips. I know that the way I mentioned before will work, but then it gets tricky to play around & modify the names of the clips, etc.

    hope this helps
    chris

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