tags:

views:

134

answers:

2

Hello.

How to avoid having embeded metadata everywhere in source code(.as or .mxml)? I have found two approaches: 1. Embed everything in css. But it is kind of difficult to extract from there:

    var soundCSSClassDec:CSSStyleDeclaration = StyleManager.getStyleDeclaration("MySound");
    var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
    var myEmbeddedSound:Sound = new MySoundClass() as Sound;      
    myEmbeddedSound.play()
  1. Embed in resource files. It is easy to extract - resourceManager.getResource("sounds","mySound"). But I feel something wrong with this approach. As i understand resourceManager was desinged for localization.

Any other ideas?

Thanks, Aleksey

+1  A: 

It's not wrong to use ResourceManager: in your case (non-localized app) you only support one language (special case of localization for N languages :).

Another approach is to load these resources over the network from some server. Of course, depending on how your application is bundled/used this approach may be inefficient.

dirkgently
But what if i have localization independent resources?Andi don't want to copy them to all supported locales.
Use the @Resource directive to access this common non-localized bundle.
dirkgently
A: 

Another option is to define an "AssetLibrary" class with lots of public static const typed to "Class"; then reference those either via binding in MXML or through simple assignment in ActionScript.

public class AssetLibrary {
    [Embed(source='/assets/image_link.png')]
    public static const IMAGE_LINK : Class;
}

Using ResourceManager is a totally valid approach too. It's actually good practice to externalize that from your application since it will make localizing it later on much easier.

cliff.meyers