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:
![](http://hi.csdn.net/attachment/201110/4/2190190_13177204048yRi.png)
pass BitmapData object:
![](http://hi.csdn.net/attachment/201110/4/2190190_13177213660bMG.png)
download the sourcefile
REFS:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d60.html
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:
![](http://hi.csdn.net/attachment/201110/4/2190190_13177204048yRi.png)
pass BitmapData object:
![](http://hi.csdn.net/attachment/201110/4/2190190_13177213660bMG.png)
download the sourcefile
REFS:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d60.html
相关文章推荐
- Empty, Unavailable, Invalid Variables Handling in Actionscript 3.0 & PHP 5+
- Detect Chinese character through out a string in Actionscript3.0
- Create a Drag and Drop Puzzle in ActionScript 3.0
- Custom Event in ActionScript3.0
- Reflection in Actionscript 3.0/Flex 2
- The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not refere
- ActionScript 3.0著名开源库 大集…
- Loading XML data using ActionScript 3.0
- Loop Through Object in Actionscript3.0
- Capture Keyboard Event in Actionscript3.0
- Looking up through Array in Actionscript 3.0
- Alternatives to Array in Actionscript3.0
- Garbage Collection in Actionscript3.0
- root, stage and timeline in ActionScript3.0
- Constructor Overloading in Actionscript 3.0
- Flash Action Script 3.0 实现 MovieClip 的拖拽
- Creating Custom Classes in LotusScript, part 1
- 积少成多Flash ActionScript 3.0(1) - 基础之数据类型、操作符和流程控制语句
- Issue of weblogic [Servlet: "action" failed to preload on startup in Web application]
- Sesing the Data Structures & Algorithms in Java