문제

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?

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top