Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 3

Registration point

When drawing a shape, whether with drawRect or drawCirc, the first two parms are the x and y offset from the 0,0 registration point. If you expect for objects added near this shape to line up with the upper left corner of the object, make sure to have the registration point of the initial object be 0,0, as shown with the square on the left in the example below.

Download the FLA file

/*===========================================================================
  Create a cyan sprite directly on its registration point. The registration point is indicated by a small yellow circle.
*/

var cyanSquare:Sprite = new Sprite();
cyanSquare.graphics.beginFill(0x00ffff);
cyanSquare.graphics.drawRect(0,0,80,80);
cyanSquare.x = 20;
cyanSquare.y = 20;
addChild(cyanSquare);

var cyanSquareRegistration:Sprite = new Sprite();
cyanSquareRegistration.graphics.beginFill(0xffff00);
cyanSquareRegistration.graphics.drawCircle(0,0,5);
cyanSquare.addChild(cyanSquareRegistration);


/*===========================================================================
  Create a red sprite 10 pixels to the right and below its registration point.
	The registration point is indicated by the small yellow circle.
*/

var redSquare:Sprite = new Sprite();
redSquare.graphics.beginFill(0xff0000);
redSquare.graphics.drawRect(10,10,80,80); // Note the "10, 10"
redSquare.x = 160;
redSquare.y = 20;
addChild(redSquare);

var redSquareRegistration:Sprite = new Sprite();
redSquareRegistration.graphics.beginFill(0xffff00);
redSquareRegistration.graphics.drawCircle(0,0,5);
redSquare.addChild(redSquareRegistration);


 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM