Flex Sprite xy Coordinates
I have a drawing that looks more or less like the attached image. image
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.
You can try using the localToGlobal
and globalToLocal
methods of the DisplayObject
class. Check it out here.
精彩评论