views:

37

answers:

1

I have this snippet of ActionScript code that is supposed to resize an image to fit the sprite: (as in rescale the image not just clip it)

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? The image isn't getting the right dimensions.

A: 

try

image.image.content.width = TheImageWidth;
image.image.content.height = TheImageHeight;
Gregor Kiddie
Nope. `image` is not a property or method of `image`.
George Edison
That's what I get for not reading the question properly! I assumed that image was an Image, not a Bitmap...Try using the transform property and assign a matrix instead of using the scaleX and Y properties.
Gregor Kiddie