3 Replies Latest reply on Jul 2, 2007 8:38 AM by gjastrab

    Image loading issues

      I am attempting to load images from another domain within my Flex application. The problem occurs when I try to obtain the width and height of the Image after I have created it. The width and height properties are zero when the Image is first created and added to a canvas, so I have to add them to a container and wait before being able use the width and height properties. I cannot use events since the properties are still zero when the Complete event fires.

      I found a workaround to this issue online where image.content.height/width is used as opposed to image.height/width. When I use this, I get security sandbox violations (but not consistently). Can anyone help?
        • 1. Re: Image loading issues
          gjastrab Level 1
          Try loading the image into a loader and then casting it to a Bitmap:

          var ldr:Loader = new Loader();
          ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);

          private function imageLoaded(evt:Event):void {
          var bmp:Bitmap = Bitmap(ldr.content);
          trace("width/height: " + bmp.width + "/" + bmp.height);
          • 2. Re: Image loading issues
            jobby-flex Level 1
            Actually, that was the first approach I tried. It *always* ends up with security exceptions. For now at least the problem appears to have disappeared. Time to stick this project into source control, I think!
            • 3. Re: Image loading issues
              gjastrab Level 1
              If you're having security problems then if you trust the content from the site, allow it's security domain:

              var context:LoaderContext = new LoaderContext();
              context.securityDomain = SecurityDomain.currentDomian;

              ldr.load(new URLRequest(path_to_image, context);