Skip to content

Instantly share code, notes, and snippets.

@mattupstate
Created June 30, 2010 05:00
Show Gist options
  • Save mattupstate/458254 to your computer and use it in GitHub Desktop.
Save mattupstate/458254 to your computer and use it in GitHub Desktop.
package
{
import flash.display.Bitmap;
import flash.display.Sprite;
public class CenteredImage extends Sprite
{
private var _image:Bitmap;
public function CenteredImage( image:Bitmap )
{
_image = image;
_image.x = _image.y = 0;
addChild( _image );
addEventListener( Event.ADDED_TO_STAGE, onAddedToStage );
}
private function onAddedToStage( event:Event ):void
{
x = parent.width * 0.5 - width * 0.5;
y = parent.height* 0.5 - height * 0.5;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment