I am having an issue with a class I’m working on. I currently load an image as a bitmap and store its data into regState:BitmapData so that I may make new instances of that image later on. When I test if I can use the loaded data at a later time with my newBitmapIntance() function, it says that regState is null. I’m lost as to why this is the case, since it works flawlessly to create an instance of itself in my loadContent() function. Any way I can successfully hold on to my loaded bitmapdata for later use?
Class so far For reference:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Loader;
import flash.display.Bitmap;
import flash.display.BitmapData;
public class MyObj extends MovieClip
{
private var regState:BitmapData;
public function MyObj()
{
}
public function loadImage(url:String):void
{
var urlRequest:URLRequest = new URLRequest(url);
var imgLdr:Loader = new Loader();
imgLdr.load(urlRequest);
imgLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, loadContent);
}
private function setRegState(temp:BitmapData):void
{
this.regState = temp.clone();
}
public function getRegState():BitmapData
{
return this.regState;
}
private function loadContent(event:Event)
{
var temp:Bitmap = event.target.content as Bitmap;
this.setRegState(temp.bitmapData);
this.addChild(newBitmapIntance());
}
public function newBitmapIntance():Bitmap
{
var temp:Bitmap = new Bitmap(this.getRegState());
return temp;
}
}
Refactored MyObj:
Use it from another class: