您的位置:首页 > 其它

Bitmap & BitmapData classes in Actionscript 3.0

2011-10-04 18:08 295 查看
A Bitmap instance has one
BitmapData instance as property.
When you use Loader to load an image, its property 'content' references to the
Bitmap object of the loaded image.
If you have one variable of
Bitmap type, you should create it by using 'new Bitmap()', then convet the 'content' to
Bitmap and assign it to your variable:
_bm = Bitmap($e.target.content); target is referencing to the the loader instance.
Of course, in some cases you have got the
BitmapData instance of the image, then you can simply pass it to
Bitmap constructor:
_bm = new Bitmap(bitmapdata);
Bitmap is complex data type, so passing a
Bitmap type variable among functions will pass it as reference, that is Actionscript natural feature. And, if you add one
Bitmap object to one Sprite, that will result in it be removed from its parent Sprite. So to pass a reference to a
Bitmap instance as parameter to function that may add it to Sprite, will not work. See the first picture.
But if you pass BitmapData instance to a function, and in that function you create a brand new
Bitmap using that
BitmapData, the BitmapData will be cloned. And that is what you expect. See the second picture.

pass Bitmap object:



pass BitmapData object:



download the sourcefile

REFS:

http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d60.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: