Flex/Actionscript image display problem.

Posted by IanH on Stack Overflow See other posts from Stack Overflow or by IanH
Published on 2010-04-20T10:08:26Z Indexed on 2010/04/20 10:13 UTC
Read the original article Hit count: 255

Filed under:
|
|
|
|

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");
        }

    }
}

© Stack Overflow or respective owner

Related posts about flex

Related posts about actionscript