tags:

views:

119

answers:

3

Hello. In one project, I have several similar applications, they just differ slightly here and there. Like some of the contained icons/images. To help organizing, I see myself [Embed]ing icons in a style like below, however the use of variables in the [Embed] metatag doesn't work. The below code is contained in a custom component, so I easily should be able to set different icons per application including the component. How do I get around this problem?

public var iconBase:String = "/icons/red/";
[Embed(iconBase + "play.png")] [Bindable] public var icon_play:Class;
[Embed(iconBase + "stop.png")] [Bindable] public var icon_stop:Class;
A: 

You have quite a few options:

  1. Write a quick code generator to build the appropriate source files.

  2. Load the icons at runtime, that way you could change the paths.

  3. Use symlinks to change where the icon files are retrieved from.

  4. Make an icon library or module and either load them at compile time or at runtime.

I think I would just load the images at runtime and change the base path.

ablerman
A: 

One option is to use the ResourceManager and put embed statements in resources files. Different apps could define different resource bundles.

Michael Brewer-Davis
+1  A: 

This should answer your question: Embedding sources dynamically.

Metadata is pre-processed by the compiler, so you can't have any variables in there.

Hope that helps, Lance

viatropos