Is it possible to add my own custom property to the flash.display.Bitmap using a public static method?
I’m trying to write a bitmap utility that does something to a bitmap, and stores a Number property onto it afterwards.
// Main.as
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
private var myBitmap:Bitmap;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
myBitmap = new _myBitmap(); // linage from library
trace(myBitmap.myNewProp); // undefined
Utils.doBitmap(myBitmap);
trace(myBitmap.myNewProp); // The Math.random() number
}
}
}
// Utils.as
package
{
public class Utils
{
public function Utils():void
{
}
public static function doBitmap(image:Bitmap):void {
// do something
image.myNewProp = Math.random();
}
}
}
I’m still learning AS3.0 OOP, so please be gentle, but I think that this can’t be done with this method. I think I have to make a new Class that extends ‘Bitmap’, add the prop there, and then in the Main.as make a new instance of that class, point to the target Bitmap, and run the method in the extended ‘Bitmap’ class (?).