Issue when creating bitmap from a movie clip in AS3
I have a problem when I try to convert a movie clip in a Bitmap. Everything works well, but some attributes don't are not in the new Bitmap.
For example, if I have a movie clip and I flip it (mc.scaleX *= -1) and the I convert it in a Bitmap it is not flip it.
import flash.geom.Matrix;
import flash.display.BitmapData;
import flash.display.Bitmap;
var box1:Box = new Box();
box1.x = 100;
box1.y = 20;
addChild( box1 );
box1.scaleX *= -1;
var box2:Box = new Box();
box2.x = 300;
box2.y = 20;
addChild( box2 );
var matrix:Matrix = new Matrix( 1, 0, 0, 1, (box1.width / 2), (box1.height / 2) );
var bitmapData:B开发者_JS百科itmapData = new BitmapData( box1.width, box1.height, true, 0xFFFFFF);
bitmapData.draw(box1, matrix, null, null, null, true);
var bitmap:Bitmap = new Bitmap( bitmapData );
addChild( bitmap );
bitmap.x = 400;
bitmap.y = 300;
If you can check this simple example you will see what I mean, the "bitmap" should be flip it is not.
Thanks for your help.
You would better get the movieclip's matrix that you want to transform and use matrix methods on it, like;
var myMatrix:Matrix = myDisplayObject.transform.matrix;
myMatrix.scale(1,-1);
myDisplayObject.transform.matrix = myMatrix;
var bitmapData:BitmapData = new BitmapData( box1.width, box1.height, true, 0xFFFFFF);
bitmapData.draw(box1, myMatrix, null, null, null, true);
This way is easier cause rotating and scaling might be complex to set on matrix.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Matrix.html?filter_flash=cs5&filter_flashplayer=10.2&filter_air=2.6
None of the transformations you apply to the DisplayObject itself will be respected when you draw()
it. If you want to scale or translate it, you need to do that to the transform matrix you are supplying to the draw call.
In this case, changing your matrix initialization to this might do the trick:
var matrix:Matrix = new Matrix( 1, 0, 0, 1, -(box1.width / 2), (box1.height / 2) );
精彩评论