1

I have got a lot of icons for an application and right now its embedded in the script tag eg:in my script tag i have

    [Embed(source="/assets/icons/save_it_icon.png")]

    [Bindable] 

    private var saveIcon:Class; 

in my flex component :

<mx:Image  id ="savePaneImg" source="{saveIcon}" 
        buttonMode="true" 
        toolTip="Save comments" 
        click="doSave();" /> 

How do i move this image source to css file for resusability across different components?

Thanks in advance

Deba
  • 63
  • 2
  • 11

3 Answers3

2

source is not a style property, you cannot set it in css. Instead I recommend you to create class, where all the images will be stored.

[Bindable]
public class IconManager {

    [Embed(source="/assets/icons/save_it_icon.png")]
    public static var saveIcon:Class;

}

Usage:

<mx:Image  id ="savePaneImg" source="{IconManager.saveIcon}" 
            buttonMode="true" 
            toolTip="Save comments" 
            click="doSave();" /> 
Timofei Davydik
  • 7,244
  • 7
  • 33
  • 59
  • +1 for the binding, but you *could* use a custom meta tag and CSS to manage the resources, only it would have to be at runtime, using reflections, and it would be a lot more complicated. – weltraumpirat Apr 18 '12 at 09:37
0

check this code, this would be help you....

public class IconSrc{
  [Embed(source="/assets/icons/save_it_icon.png")] 
  [Bindable]
  private var _icon1:Class
  public static function getSource(icon:String):Class{
    switch(icon){
     case "icon1": return _icon1;break;
      .
      .
      .
    }
  }
}

<mx:Image  id ="savePaneImg" source="{IconSrc.getSource('icon1')}"  
            buttonMode="true"  
            toolTip="Save comments"  
            click="doSave();" /> 
ashoo_bob
  • 162
  • 3
0

I suggest you check this post Howto embed images in Actionscript 3 / Flex 3 the right way?

Create a Class and store all your assets in there as static variables. Then access them from all over the place.

Community
  • 1
  • 1
Adrian Pirvulescu
  • 4,308
  • 3
  • 30
  • 47