1 Reply Latest reply on Nov 14, 2007 7:39 PM by atta707

    Setting 'source' of Image component programmatically

      How do you change the source of an mx:Image component programmatically in ActionScript?

      I have an image like this:
      <mx:Image id="myImage" source="@Embed(source='image1.png')" />

      Then I want to change this in my actionscript to image2.png. Why does not the following code work?

      myImage.source = "@Embed(source='image1.png')";

      The image won't load, it just displays a small square icon. I am sure that the path is correct because it works when I use the Embed statement in the component declaration.

      I appreciate your help!
        • 1. Re: Setting 'source' of Image component programmatically
          atta707 Level 2
          The line:

          <mx:Image id="myImage" source="@Embed(source='image1.png')" />

          embeds the image into your SWF file at compile time. To change the source at run time, you'll try something like:

          myImage.source = "images/image1.png";

          Where images is your folder on the root of web application context you're in and image1.png is the image to be loaded.

          Here is from image class help from docs:
          The URL, object, class or string name of a class to load as the content. The source property takes the following form: