views:

172

answers:

1

I'm trying to extend the Image class but hit a problem that I can't get past. I have a private image (img) that loads an image and a function that takes that image and copies it onto the parent.

The debug function "copyit2" displays the image fine (so I know it's loaded OK). But the function "copyit" doesn't work - it just displays a white rectangle. I can't see how to make copyit work so that the original image is copied to the BitmapData and then subsequenty copied onto the parent?

(The idea is to do some processing on the Bitmap data before it is displayed, although this isn't shown here to keep the example simple.)

I suspect it is something to do with the security of loading images, but I'm loading it from the same server as the application is run from - so this shouldn't be a problem?

Thanks for any help anyone can provide.
Ian

package zoomapackage
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.net.*;

    import mx.controls.Image;
    import mx.events.FlexEvent;

    public dynamic class Zooma extends Image
    {
        private var img:Image;

        public function copyit():void {
            var imgObj:BitmapData = new BitmapData(img.content.width, img.content.height, false);

            imgObj.draw(img);

            var matrix:Matrix = new Matrix();
            this.graphics.beginBitmapFill(imgObj, matrix, false,true);
            this.graphics.drawRect(0, 0, this.width , this.height);
            this.graphics.endFill();
        }

        public function copyit2():void {
            this.source = img.source;
        }

        public function Zooma()
        {
            super();
            img = new Image();
            img.load("http://localhost/Koala.jpg");
        }

    }
}
A: 

Fixed it! (Including this in case anyone finds it useful)

The line:

imgObj.draw(img);

works if I change it to:

imgObj.draw(img.content);

Lost 2 days of my life on that :-(

IanH