3 Replies Latest reply on Dec 31, 2010 5:35 AM by flex2008

    BitmapImage source with actionScript

    Maximist Level 1

      Hallo, I have a little problem. I have a BitmapImage component:

       

      <s:BitmapImage id="loghettino" source="@Embed('../images/loghettinoMiePagine_bianco.png')" smooth="true"/>

       

      When i give the source with mxml everything works fine and i see the image. What i want to do is to change the source dinamically in actionscript.

       

      So i created this in mxml:

       

      <s:BitmapImage id="loghettino" smooth="true"/>

       

      Then, i am giving the source in this way:

       

      this.loghettino.source = "@Embed('../images/loghettinoMiePagine_bianco.png')";

       

      But it doesn't work, i can't see the image... I tried to assign that in initialize event, in render event, but nothing. Why it happen??

       

      Thx for all

       

      Max

        • 1. Re: BitmapImage source with actionScript
          Maximist Level 1

          Ok, now i know that with as3 the way to assign an image is this:

           

          [Embed("../images/loghettinoMiePagine_bianco.png")]Êprivate var someImage:Class;

           

          var myImage:BitmapImage = new BitmapImage();

          myImage.source = this.someImage;

           

           

          This works but how can i change "../images/loghettinoMiePagine_bianco.png" dinamically??  i don't know how to do that

           

          Max

          • 2. Re: BitmapImage source with actionScript
            saisri2k2 Level 4

            you dont have to embed the images.. just give a path to the image location in the source. or declare multiple embed classes in the same file and change the source dynamically.

             

            somthing like this will work

             

            <s:BitmapImage source="images/Add-icon.jpg"/>

            • 3. Re: BitmapImage source with actionScript
              flex2008 Level 3

              Embedding assets is done at compile time.Hence you cannot have a dynamic path while embedding.What you can do is embed all the possible images into separate classes and assign the approppriate source as the case may be.But this can increase the size of the swf if there are large number of images and each one is huge sized.Another way is not to use image and use the path of the image as the source.Then you can change the path dynamically.But for this to work,you need to copy all the images to whereever you are deploying the flex app and ensure that the path is used correctly.

               

              Hope I answered your query.