开发者

flash as3 understanding matrix

I'm trying to understand flash's matrix functionality, as I think it will help me solve this problem:

I have a series of boxes laid out into 4 columns. I want to scale one column (say, by a factor of 2) - and figure out what its new width will be so I can move the other columns appropriately so that they are not covered by the newly scaled column. How do I figure that out using a matrix? Are matrices really necessary, and if so, when and why? It seems like I could just take something's width, multiple it by 2, and use that value to move all the rest of the columns - why is a matrix better? If I use the code below, how do I trace the width of something using the theoretical matrix:

var matrix:Matrix = new Matrix();
var scaleFactor:Number = 2;
matrix.scale(scaleFactor, scaleFactor);
//need to trace an object's width assuming the matrix would be applied to it, witho开发者_Go百科ut actually applying it here.


What you're doing there can more easily be done using scaleX and scaleY like this:

thing.scaleX = thing.scaleY = 2;

There's no real advantage (that I can think of) to using a Matrix for achieving results like the above; there's simpler functionality built into DisplayObjects themselves. The only time I'd really use a Matrix to change the shape of an object would be to skew or shear it.

That said, matrices are extremely useful as a parameter of BitmapData.draw() to manipulate the result graphics - I use Matrix.translate() quite a bit here.

I'd look at this as it's quite clear:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/geom/Matrix.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜