Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force compile-time linking of all classes in a SWC

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.)

like image 773
aaaidan Avatar asked Jun 08 '10 03:06

aaaidan


3 Answers

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;
like image 97
Ender Avatar answered Sep 30 '22 21:09

Ender


There's no way to pull in and embed every class in an SWC by default in Flash CS4/CS5, but you may be able to do this with:

FlashDevelop

As you already know, this program's project properties has compiler options that differentiate between:

  • SWC Libraries: "Links SWC files to the resultin gapplication SWF file. The compiler only links in those classes for the SWC file that are required."
  • SWC Include Libraries: "Links ALL classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used."

That second option "SWC Include Libraries" could be useful, because if you simply compile your FLA as-is into a SWC, then put that SWC and your other SWC into FlashDevelop as SWC Include Libraries, it should compile/merge them into a single SWF that will work like you want.

FlashDevelop could also simply help you build a hard-coded list of Classes in an SWC, because if you link in the SWC as a SWC Library, it will show up in the project explorer, and you can see a list of all the classes in the SWC. You can also right click each class and choose "Insert Into Document", and it will insert the full class name. If you do that, then press semi-colon enter, you will have your first class reference. Keep your mouse over the class list in the project settings and repeat this for every class in the list. It only takes a few minutes to do this for hundreds of classes, which makes creating such a list easier. It would be even faster if the thing would let you insert more than one at once, but it doesn't seem to.

Your only other option, which you said you weren't interested in for no given reason, is Runtime Shared Libraries (RSLs). It's really not that big a deal to load the file in separately, but only if you properly handle the load process and any errors that might occur. It will add some complexity to your project, and may require some extra thought, but I'd seriously consider it as an option. See the "Application Domain Inheritance" section at www.senocular.com/flash/tutorials/contentdomains/?page=2 for more information.

like image 25
Triynko Avatar answered Sep 30 '22 20:09

Triynko


I am probably missing something but isn't it a case of using -include-libraries rather than library-path option of the compiler, this is what the adobe doc says about the option

Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used.

Contrast this option with the library-path option that includes only those classes that are referenced at compile time.

Adobe Documentation

I am new to all this so be gentle when you shoot me down in flames :)

like image 44
default_avatar Avatar answered Sep 30 '22 19:09

default_avatar