How come this image won't resize to fit the sprite?

Posted by George Edison on Stack Overflow See other posts from Stack Overflow or by George Edison
Published on 2010-04-13T03:51:02Z Indexed on 2010/04/13 3:52 UTC
Read the original article Hit count: 318

Filed under:
|
|
|

I have this snippet of ActionScript code that is supposed to resize an image to fit the sprite:

package 
{
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.events.Event;

    public class Main extends Sprite 
    {
        [Embed(source = 'img.png')]
        private var TheImage:Class;

        public static const  TheImageWidth:Number = 1300;
        public static const TheImageHeight:Number = 1300;

        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);
            // entry point

            var image:Bitmap = new TheImage();

            addChild(image);

            image.scaleX = width / TheImageWidth;
            image.scaleY = height / TheImageHeight;
        }

    }

}

Why isn't it working?

© Stack Overflow or respective owner

Related posts about actionscript

Related posts about flex