R – Flex: Placing items on the canvas element

actionscript-3apache-flex

I am writing simple game on flex. In the game there are 2 objects Board and Stone (both are extended from the Canvas super class)

When I started to place Stones instances to the Board Canvas, I come across the problem, I can't understand how to set Stone on the defined position on the board.

So if for example board (canvas) has following attributes: x = 25, y = 25, height = 100, width = 100

How can I for example place a Stone (canvas) in a point 25, 25.

Is there a way to use local board coordinates?

Best Answer

board.addChild(stone);
stone.x = 25;
stone.y = 25;

Btw, you need not use Canvas for these objects - a Shape or Sprite would be enough. Add the Board sprite to the flex app using rawChildren.addChild(board); Canvas is a Container class for flex ui components.