I’m so 2.0 Using Flex Components/Classes in ActionScript 3 Projects - ResourceBundle error
Aug 29

So one of the most annoying things I’ve ever come across in Flash/ActionScript development is dealing with dynamically loaded images from other domains and accessing their inner BitmapData. In enterprise apps, it’s almost never the case that all of your images are coming from the same domain.

Recently, I had a project come up that asked me once again to deal with this issue. The goal was to get JPGs to smoothly zoom slowly something like the Ken Burns effect. The problem was that the images were all hosted in a completely different domain. In my ignorance, I threw my hands up and said, “Nope, sorry it’s going to be a crappy effect. You can never get that sort of thing to work without getting at the BitmapData. Which is impossible because it’s coming from another site.”

At which point Arpit pointed out that in AS3 we now have this absolutely beautiful LoaderContext class. I know I’m late to the game on this one, but I wanted to blog it because I hate when this stuff isn’t easily found on the web and the more we blog, the easier it is to find.

The solution couldn’t be easier. Here’s how you get around it:

  1. Make sure the domain which is serving out the images has a crossdomain.xml file at its root.
    1. If you’re unfamiliar with crossdomain policy files or the security sandbox in general, check out this security white paper from Adobe.
  2. Add the SmoothImage component by Ben Longoria from the Adobe Flex cookbook beta.
  3. Add the SmoothImage component to your project.
    ...
    <foo:SmoothImage id="imageDisplayer">
    width="308" height="274"
    complete="onImageChangeComplete(event);"
    />
    ...
  4. Add a LoaderContext with a checkPolicy property set to true. See the docs for more info.
    ...
    <foo:SmoothImage id="imageDisplayer">
    width="308" height="274"
    loaderContext=”{new LoaderContext(true)}”
    complete=”onImageChangeComplete(event);”
    />
  5. Sigh your relief that you will never again have to deal with the hell that is cross domain image manipulation.

Links in this blog:

8 Responses to “Smoothing BitmapData in an Image Component from other domains”

  1. code zen » Blog Archive » Ever used LoaderContext? Says:

    [...] another Flash/Flex developer on my team, has a good poston his blog on the LoaderContext class and using it for getting access to the BitmapData object of [...]

  2. Corey Says:

    Yep, very good tool for AS3 - but the limitation imposed by Adobe still drives me crazy. You still can’t “mash-up” images from different domains (flickr, etc.) unless said domains have a cross-domain file in place. Still a buzz killer imho.

    Does anyone know exactly why in the world Adobe is preventing , or rather, not providing, a high quality filtered scale option for cross domain images? It’s completely ridiculous and truly a competitive hit (with the advent of Silverlight, etc.) no ?

  3. Corey Says:

    Another good post on the matter. http://www.abdulqabiz.com/blog/archives/flash_and_actionscript/bitmapdatadraw.php

    For what it’s worth I’m solving the issue with a pool of squid image proxies (www.circavie.com).

  4. Timo Says:

    I can’t get the smoothimage work! I mean that from Ben Longoria. What the hell is matter with it!

    Error: Type was not found or was not a compile-time constant: SmoothImage.

  5. kfitzpatrick Says:

    @Timo

    That doesn’t sound like there’s anything wrong with the class at all.

    That sounds like you haven’t imported the SmoothImage class correctly. Have you placed the file somewhere in your source folder and imported the class within the source file in which you’re instantiating it?

  6. Wahoo Says:

    Thank you for sharing!

  7. Suavizar imagem no Flex/Flash | Igor Costa Says:

    [...] Existem outros links de referĂȘncias que valem o click: http://www.kevin-fitzpatrick.net/blog/?p=10 [...]

  8. Suavizar imagem no Flex/Flash | Igor Costa Says:

    [...] Existem outros links de referĂȘncias que valem o click: http://www.kevin-fitzpatrick.net/blog/?p=10 [...]

Leave a Reply