Scale, width/height and graphics.moveTo (ActionScript 3.0)

This is a tricky issue. When you have a Shape or a Sprite (AS3) object and you want to change its width or height (without using a transformation matrix), you can do it by changing the scale property (using percentage) or the width/height property (using pixel units). This second method will also change the scale, as you can read here,  and both methods change the object coordinate system, as you can see here. Therefore, if you have used the graphics.moveTo(x,y) function, its parameters will also be modified according the new coordinate system. Due this scale change, the graphics will NOT move to a point that has (global) coordinates (x,y), but will move to a point with (global) coordinates multiplied by the scale value (x*scaleX,y*scaleY).

Example (you should understand first how flash coordinate systems works):

var myobject:Sprite = new Sprite();

myobject.x = 0;

myobject.y = 0;

myobject.graphics.moveTo(10,10);

myobject.scaleX = 2; // or myobject.width = myobject.width * 2;

After this change, the graphics of myobject instead of moving to the point (10,10) in the global system, will move to the point (20,10). The X (global) coordinate was multiplied by the value of myobject.scaleX .

If you think, this is how flash coordinate system works in general. The difference is in the scale properties, which have by default the value of 1. Therefore, any coordinates (X,Y) multiplied by the scale (1,1), will result in the same values (X,Y). But if you change the scale value, the coordinates (X,Y) will also change.

Advertisements

One Response to Scale, width/height and graphics.moveTo (ActionScript 3.0)

  1. Vish says:

    Thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: