7 Replies Latest reply on Nov 22, 2006 11:45 AM by mpwalker

    variables for linkage

      Ok, I have an attached object on the stage with the linkage name red1. On an event, varable _root.game.piecetomove = "red1". If I want flash to trace the x coordinates of the object with the linkage name "red1" why can't I simply put

      trace (_root.game.piecetomove._x);

      ? It keeps returning an undefined value. Any help would be greatly appreciated.
        • 1. Re: variables for linkage
          kglad Adobe Community Professional & MVP
          because piecetomove is a string variable. flash doesn't understand that you want to convert this string into an object. you must instruct flash to do so. using array notation will work:

          • 2. Re: variables for linkage
            mpwalker Level 1
            how would I define the variable then? I tried changing the trace code to what you gave me and I still couldn't get anything...
            • 3. Re: variables for linkage
              crazyjoemilan Level 2
              _root.fullArray = ["red1", "red2", "red3"];
              _root.startVar = 0;
              Mbutton.onRelease = function() {
              _root.game.piecetomove = _root.fullArray[_root.startVar];
              if (_root.startVar == 2) {
              _root.startVar = 0;
              } else {

              Okay, hopefully you have 3 pieces named red1, red2, red3. Then you need to make a button instance named Mbutton. The above code will show whats off.
              • 4. Re: variables for linkage
                mpwalker Level 1
                I'm sorry, I still don't understand, it is still not recognizing that I want to refer to the object not the string on the code checking for the coordinates. All I need to know is how to define a string variable (red1) and then use the variable to have flash reference the object for "red1".
                • 5. Re: variables for linkage
                  crazyjoemilan Level 2
                  okay, what the code I pasted says is that its a problem of how you're referencing it.
                  When I built a little movie to emulate your problem, I used....


                  and got "undefined". However, when I used .....


                  I got a number. Does that help?
                  • 6. Re: variables for linkage
                    mpwalker Level 1
                    Thanks for hanging in there with me, but (no surprises) I'm still having problems. Here's the little bit of code inside my application that is giving me the problem. Can you tell me why this traces as undefined?

                    onClipEvent (mouseUp) {
                    if (_root.game.xmouse == _root.game.red1x and _root.game.ymouse == _root.game.red1y){
                    _root.game.piecetomove = "red1";
                    _root.game.piecetomovex=Math.round(((_root.red1._x+_root.game.tileW/2)/_root.game.tileW)- 1);
                    _root.game.piecetomovey=Math.round(((_root.red1._y+_root.game.tileH/2)/_root.game.tileH)- 1);
                    trace (_root.game[_root.game.piecetomove]._x);

                    If I put: trace(_root.game.piecetomove); I get "red1".
                    If I put trace(_root.game.red1) I get the correct integer.
                    • 7. Re: variables for linkage
                      mpwalker Level 1
                      Nevermind, I figured it out. I'm a little embarrassed to admit it but I have the red1 object in the _root object not the game object.
                      Thanks for clearing up my problem though!