StageAwareSprite
January 3rd, 2010
Here’s another handy little object. Again, it’s pretty trivial but might save you 10 minutes.
Extend StageAwareSprite instead of Sprite to get automatic handing of any stage-related activity. This simply saves you all the hassle of adding and removing the event listeners yourself.
The class has protected addedToStage, removedFromStage and stageResize methods that are triggered as you expect but which do nothing by default. They are intended to be extended so you can create your own custom behaviours.
Files:
com.aderowbotham.utils.StageAwareSprite
StageSpriteDemo.zip
Example usage – this could be the base class for a library object:
package {
import com.aderowbotham.utils.StageAwareSprite;
public class Demo extends StageAwareSprite {
public function Demo() {
super();
}
override protected function addedToStage():void{
trace("added to stage");
trace("stageWidth = "+stageWidth,", stageHeight = "+stageHeight);
}
override protected function removedFromStage():void{
trace("removed from stage");
}
override protected function stageResize():void{
trace("stage resized to: "+stageWidth+", "+stageHeight);
}
}
}
January 3rd, 2010 at 17:38
Nice work..