Question

I'm trying to load a local SWF file and use the classes in that SWF (its a code only SWF, nothing in library).

Here's the code that loads the library:

var AD:ApplicationDomain = ApplicationDomain.currentDomain;
var context:LoaderContext = new LoaderContext(false, AD);

SA_gamecore_loader = new Loader();
SA_gamecore_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameCoreLibraryDataComplete);
SA_gamecore_loader.load(new URLRequest("GameCore.swf"), context);

Here's the code that tries to instantiate a class from GameCore.swf:

var test:Class = GetClassFromDefinition("MenuArt") as Class;
var testInstance:Object = new test();

public function GetClassFromDefinition(theStr:String):Object
{
    var theClass:Object;
    try
    {
        theClass = GameCoreLibraryData.applicationDomain.getDefinition(theStr);
    }
    catch(e:ReferenceError)
    {
        trace(e);
        return null;
    }
    return theClass;
}

And this is the message that's traced:

ReferenceError: Error #1065: Variable MenuArt is not defined.

The GameCore.swf is in the same location as the parent swf. I'm using Flash Develop if that helps. Anyone able to point out what I'm doing wrong?

Was it helpful?

Solution

Finally figured out the problem. I had to include the package name in the getDefinition call. So in my case:

var test:Class = GetClassFromDefinition("test.MenuArt") as Class;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top