Alternative for getDefinitionByName

1.8k Views Asked by At

In the past, there was a simple trick, to include the mxmlc module by adding the following line to the makefile:

-include-libraries “/absolute/path/to/my/assets/assets.swc” 

This gave you the ability to use getDefinitionByName, an helper function to access the embedded swc asset-library (instead of creating hand-written classes all assets).

Unfortunately, this has stopped working since . Does anybody know another solution?

3

There are 3 best solutions below

0
On BEST ANSWER

Unfortunately, the only workaround I have found is to explicitly refer each of asset classes somewhere in the code. You may create dummy class like this:

public class AssetsExporter extends Sprite
{   
  public static function export()
  {
    AssetClass1;
    AssetClass2;
    //etc

    trace( "DEBUG AssetsExporter.export()" );
  }
}

Specify this class as Document class in Flash IDE, so it will be compiled into the resulting swc. Then in the main code of your application call

AssetsExporter.export();

After doing this you will be able to use getDefinitionByName().

3
On

You can add them to the libraries in the publish settings.

Publish Settings

(Image from http://wiki.gigya.com/ via Google Images)

By the way, if you use SWC files, you can also do

new somepackage.SomeClass();

instead of

new getDefinitionByName("somepackage.SomeClass")

where applicable. This is because SWC files are included at compile time, not runtime.

0
On

Even though you can change a compiler setting manually, its easy if you are using FlashDevelop as this is very simple to fix.

Right click your included swc from the Project list. Choose options then "include library (complete library)".

..you can now use getDefinitionByName to get an unreferenced class from your swc file.