03.05.2013 Views

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

ActionScript 2.0 Language Reference - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example<br />

The following example creates three matrixes that define transformations for three rectangle<br />

movie clips. The first two matrixes rotate45Matrix <strong>and</strong> doubleScaleMatrix are applied to<br />

the two rectangles rectangleMc_1 <strong>and</strong> rectangleMc_2. Then the third matrix is created<br />

using the concat() method on rotate45Matrix <strong>and</strong> doubleScaleMatrix to create<br />

scaleAndRotateMatrix. This matrix is then applied to rectangleMc_3 to scale <strong>and</strong> rotate<br />

it.<br />

import flash.geom.Matrix;<br />

import flash.geom.Transform;<br />

var rectangleMc_0:MovieClip = createRectangle(20, 80, 0x000000);<br />

var rectangleMc_1:MovieClip = createRectangle(20, 80, 0xFF0000);<br />

var rectangleMc_2:MovieClip = createRectangle(20, 80, 0x00FF00);<br />

var rectangleMc_3:MovieClip = createRectangle(20, 80, 0x0000FF);<br />

var rectangleTrans_1:Transform = new Transform(rectangleMc_1);<br />

var rectangleTrans_2:Transform = new Transform(rectangleMc_2);<br />

var rectangleTrans_3:Transform = new Transform(rectangleMc_3);<br />

var rotate45Matrix:Matrix = new Matrix();<br />

rotate45Matrix.rotate(Math.PI/4);<br />

rectangleTrans_1.matrix = rotate45Matrix;<br />

rectangleMc_1._x = 100;<br />

trace(rotate45Matrix.toString()); // (a=0.707106781186548,<br />

b=0.707106781186547, c=-0.707106781186547, d=0.707106781186548, tx=0,<br />

ty=0)<br />

var doubleScaleMatrix:Matrix = new Matrix();<br />

doubleScaleMatrix.scale(2, 2);<br />

rectangleTrans_2.matrix = doubleScaleMatrix;<br />

rectangleMc_2._x = 200;<br />

trace(doubleScaleMatrix.toString()); // (a=2, b=0, c=0, d=2, tx=0, ty=0)<br />

var scaleAndRotateMatrix:Matrix = doubleScaleMatrix.clone();<br />

scaleAndRotateMatrix.concat(rotate45Matrix);<br />

rectangleTrans_3.matrix = scaleAndRotateMatrix;<br />

rectangleMc_3._x = 300;<br />

trace(scaleAndRotateMatrix.toString()); // (a=1.4142135623731,<br />

b=1.41421356237309, c=-1.41421356237309, d=1.4142135623731, tx=0, ty=0)<br />

Matrix (flash.geom.Matrix) 779

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!