2 Replies Latest reply on Jun 2, 2010 2:21 AM by Ianvn.za

    Sprite Coordinates

    Ianvn.za

      Hi,

       

      I have a drawing that looks more or less like the attached image.

      Sprites.png

      The orange square is the currently selected selected sprite.

       

      The sprites are all draws from coordinates that i receive from XML.

       

      var sprObject:Sprite = new Sprite();

       

      sprObject.graphics.beginFill(itemList.c.toString());

      sprObject.name = strName;

       

      sprObject.graphics.moveTo(iX, iY);

      sprObject.graphics.lineTo(iX2, iY2);

      sprObject.graphics.lineTo(iX3, iY3);
      sprObject.graphics.lineTo(iX4, iY4);
      sprObject.graphics.lineTo(iX, iX);
      sprObject.graphics.endFill();
      mainUI.addChild(sprObject);     // mainUI is a mx:UIComponent
      g_Sprite.push(sprObject);        // array of sprites.
      What I want to do is the following.
      If I'm currently on the orange square and I use my keyboard direction buttons (up/down/left/right).
      I want to deselect the current sprite and select the next sprite in the appropriate direction.
      The problem I'm having is that I cannot get the x and y coordinates of the drawn sprites.
      If I look in the array, the x and y coordinates of the sprites are all 0.
      If I can retrieve that I can write an algorithm to determine the next sprite to select.
      Any help would be appreciated.
        • 1. Re: Sprite Coordinates
          Rdsingh Ldh

          hi,

           

          u can do one thing when u are attaching the childs in the UI component i.e 'mainUI'........ just set the name of each of sprite u add to the UI component....  Once u have done with that...... then by taking the refence of the selected object through its name... u will be able to get the x and y coordinates of the Sprite object...........

           

          A sample would look like:

           

           

          var ref = mainUI.getChildByName(name_of_sprite);

           

          trace(ref.x)

          trace(ref.y)..........

           

          This will give u x and y coordinates of the Sprite object...........

           

          Hopefully this will solve ur purpose.....................

          • 2. Re: Sprite Coordinates
            Ianvn.za Level 1

            Thanks for your reply.

             

            I tried the suggested method and I get all the information like width and height but the x and y are still 0.