Question

I'm building an air mobile app and want to load a different set of graphics for SD and HD devices, I have my resources classes setup as follows:

SD graphics

package view.graphics 
{
    public class MainMenuGraphicsSD extends GraphicsResource
    {
        [Embed(source = "../../../lib/graphics/mainmenu/logo.png")]
        public static const logo:Class;
    }   
}

And then the HD

package view.graphics 
{
    public class MainMenuGraphicsHD extends GraphicsResource
    {
        [Embed(source = "../../../lib/graphics/mainmenu/logoHD.png")]
        public static const logo:Class;
    }   
}

And then in the main menu class I have at the top

import view.graphics.MainMenuGraphicsHD;
import view.graphics.MainMenuGraphicsSD;

I pass the class Name to the asset manager to enqueue the items inside, and preload them...

Assets.getInstance().assets.enqueue( isHD ? MainMenuGraphicsHD : MainMenuGraphicsSD);

would all the assets get embedded but only the relevant definition referenced or should it work how I want it to and only load the relevant resources?

Was it helpful?

Solution

With this code both assets will be embedded, and only the relevant asset will be instantiated. If you want to make these resources externally loaded in order to reduce the SWF size, you need to play with Loaders and then reference the content via loader.content. You may, for example, compile two SWFs containing assets only, one for SD and one for HD, load the relevant SWF once the resolution is established, and instantiate classes from there using the way described in this question's answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top