Flash - can't access classes in another SWF

Posted by Ashley Muller on Stack Overflow See other posts from Stack Overflow or by Ashley Muller
Published on 2011-02-23T05:26:01Z Indexed on 2011/02/23 7:24 UTC
Read the original article Hit count: 208

Filed under:
|
|
|
|

Hi,

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?

© Stack Overflow or respective owner

Related posts about flash

Related posts about actionscript-3