Bitmap & BitmapData classes in Actionscript 3.0

来源:互联网 发布:万维网域名注册 编辑:程序博客网 时间:2024/05/01 08:03

  • A Bitmap instance has oneBitmapData instance as property.
  • When you use Loader to load an image, its property 'content' references to theBitmap 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' toBitmap 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 toBitmap constructor: _bm = new Bitmap(bitmapdata);
  •  Bitmap is complex data type, so passing aBitmap type variable among functions will pass it as reference, that is Actionscript natural feature. And, if you add oneBitmap object to one Sprite, that will result in it be removed from its parent Sprite. So to pass a reference to aBitmap 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 newBitmap using that BitmapData, the BitmapData will be cloned. And that is what you expect. See the second picture.



pass Bitmap object:

pass-bitmap


pass BitmapData object:


pass-bitmapdata


download the sourcefile


REFS:


http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d60.html

原创粉丝点击