views:

207

answers:

2

Using Flash CS4, I am making a game that has a dozen or so sounds and a couple of music tracks. To cut down on publish/compile time, I have moved the sounds and music into an (external) SWC, which is located in a "Library Path" for the project. This works, but with a caveat...

Until before I externalised the assets, I had been dynamically instantiating the Sound objects of the embedded sound by getting their classes with getDefinitionByName.

// something like...
var soundSubClass:Class = Class(getDefinitionByName(soundClassName));
var mySound:Sound = new soundSubClass();

But now that they're located in an external SWC, I need to have "concrete" references to the classes in order to load them like this, otherwise they are not included in the published SWF, and there is a runtime error when getDefinitionByName tries to get a class that doesn't exist.

So, my question: in Flash Professional CS4, is there any way to force a library's assets to be included, regardless of whether they are statically linked?

FlashDevelop has a compiler option "SWC Include Libraries", which is exactly what I want, and is distinct from the "SWC Libraries" option. The description of the "SWC Include Libraries" option is "Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used."

(Also, it's important to me that all the assets are contained within the one compiled SWF. Linking at runtime isn't what I'm after.)

A: 

You can supply the path of your assets.swc file, in ActionScript Properties, and that should work and load assets at runtime.

Chetan Sachdev
Indeed, this is how I've set it up at the moment, but it doesn't include the classes/assets in the published swf unless they have a static ("concrete") link to them.
aaaidan
+2  A: 

Unfortunately, I don't think so. I hope this is fixed in CS5, but I wouldn't bet on it...

The current (aggravating) standard is to have a manifest class in your SWC that references all the root classes in the rest of the library:

public class MyLibManifest {
    public static function manifest():void {
         var class1:Class = Class1;
         var class2:Class = Class2;
         // etc...
    }
}

Then, somewhere in your main .fla...

import com.mylibrary.MyLibManifest;

...

var myLibrary:Class = MyLibManifest;
Ender
Ah, bugger. What you've described is a nice structured version of how I'm doing things right now, but it still doesn't make me happy. Anyway, I'll accept your answer soon (unless someone else tells me what I wanna hear). Cheers
aaaidan