0
votes

I'm loading a .swf and trying to find a class based on an embedded xml document in it. I've looked this problem up endlessly and everyone has either said "Your class isn't public", "Your classname is interfering with your document class", or "You aren't using the same ApplicationDomain", none of which are true. Here's my code:

In CoCMain.as, with a CoCMod.fla:

    private function pluginLoadingComplete(e:Event):void {
        var testXML:XML = new XML(new e.target.content.description);
        trace(e.target.applicationDomain.hasDefinition("blah.blaah.testPlugin.TestMain"));//returns false
        trace(ApplicationDomain.currentDomain.hasDefinition("blah.blaah.testPlugin.TestMain"));//returns false
        trace(testXML.main[0]);//returns blah.blaah.testPlugin.TestMain
        var pluginClass:Class = e.target.applicationDomain.getDefinition(testXML.main[0]) as Class;//error here
    }

And in TestMain.as, with a TestMod.fla (this is the swf I am loading):

package blah.blaah.testPlugin {

    public class TestMain {
        public function TestMain():void {
            super();
        }       

        public function onEnable():void {
            trace("blah");
        }
    }   
}

And in frame 1 of TestMod.fla:

import blah.blaah.testPlugin.TestMain;

[Embed(source = 'main.xml', mimeType = "application/octet-stream")]
const description:Class;

The xml file:

<mod>
    <name>Test Mod</name>
    <description>Please ignore</description>
    <author>Bleachisback</author>
    <version>1.0</version>
    <main>blah.blaah.testPlugin.TestMain</main>
</mod>

The error I am getting:

ReferenceError: Error #1065: Variable TestMain is not defined.
    at flash.system::ApplicationDomain/getDefinition()
    at me.bleachisback.cocMod::CoCMain/pluginLoadingComplete()
2

2 Answers

0
votes

This sounds like a similar problem to what I encountered - where you're trying to dynamically create an instance from the descriptive name.

If you don't explicitly instantiate an instance of your target class, the compiler won't include your target class in the build, so the class doesn't exist (hence your error). So, you could add the line

var xyz:TestMain = new TestMain();

but that sort of defeats the purpose...

You can force the compiler to include your class by using the includes directive, with the list of classes that must be included.

0
votes

Did you try this?

var pluginClass:Class = e.target.applicationDomain.getDefinition(testXML.main.text().toString()) as Class;