Let's assume we have the following class :
public class ImageButton extends MovieClip
{
private var bmpNormal:BitmapData;
// ------- Properties -------
public function get BmpNormal():BitmapData { return bmpNormal; }
public function set BmpNormal(value:BitmapData):void { bmpNormal = value; }
public function ImageButton()
{
}
public function Draw()
{
var bm:Bitmap = new Bitmap(BmpNormal);
this.addChild(bm);
}
}
An instance of ImageButton is added with the following code:
var imgBtn:ImageButton = new ImageButton();
imgBtn.BmpNormal = new onstageBMPData(0,0);
imgBtn.Draw(); //<- No need for this line ??
this.addChild(imgBtn);
Now the problem/question is that the draw() method isn't really necessary ... There has to be a way to execute the draw routine when the class is inited or loaded, so the resulting code would be:
var imgBtn:ImageButton = new ImageButton();
imgBtn.BmpNormal = new onstageBMPData(0,0);
this.addChild(imgBtn);
We tried using the INIT, ADDED or RENDER events, but that doesn't seem to work
public function ImageButton()
{
this.addEventListener(Event.RENDER, onAdded, false, 0, false );
}