1 Reply Latest reply on Apr 15, 2009 3:53 AM by hiya

    Image re-use in flex



      I am trying out FlexBuilder 3 and seeing if I can put together a first project.


      The layout is in module format, whereby the main application SWF loads modules as necessary.


      The problem I have is that I am trying to find a tidy way to re-use embedded images.


      So far, I have found the following website :

      http://stackoverflow.com/questions/87557/in-flex-as3-how-do-i-get-a-class-definition-of-an -embedded-asset-with-getdefinit


      However I've tried implementing both methods and cannot get the image to load.


      In my last implementation attempt, I've tried the following.


      (1) A class called SVImages


      package com.test.serviceview
          import flash.display.Bitmap;
          public class SVImages
              [Embed(source="assets/images/1938022_small.jpg")] private static var WelcomeImage:Class;
              private var _image:Bitmap;
              public function SVImages(name:String)
                  //_image = new this[name]() as Bitmap;
                  var classDef:Class = SVImages[name] as Class;
                  _image = new classDef() as Bitmap;   


      (2) Within one of my modules


                  import com.test.serviceview.SVImages;
                  public var Handshake:SVImages = new SVImages("WelcomeImage");

      <mx:Image id="welcomeimg" source="{ WelcomeImage}" height="174" width="231" y="-2" horizontalCenter="-115.5"/>




      All this compiles fine and there are no problems notified in Flex Builder.  The text label elements of my module show up fine in the application, but the image just does not appear.  I have tried changing the image source to reflect both the relative directory compared to the main application, and the relative directory compared to the module.  Neither option worked.  The image definitley exists because I can browse to it.


      The problem is, I am both a Flex newbie and an ActionScript newbie.... so I don't know where to start looking for what's wrong !


      Thanks for your help