2
votes

I have a main project, and i want to load another project's swf into it:

//loader code in Main class of main project
var url:URLRequest = new URLRequest("../src/components/TextTool.swf");      
var ttWrapper:UIComponent = new UIComponent();
var ldr:SWFLoader = new SWFLoader(); 
var context:LoaderContext   = new LoaderContext();
if (Security.sandboxType == Security.LOCAL_TRUSTED) {
context.applicationDomain   = new ApplicationDomain(ApplicationDomain.currentDomain);
    }         ldr.source = "../src/components/TextTool.swf";
        ldr.loaderContext = context;
        ldr.addEventListener(Event.COMPLETE, onLoadComplete);
        ldr.load();     
        can.addElement(ldr);

Here's the code of the Main class of the second project:

<?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:stark="stark.*" name="textModule" >    
        <stark:TextTool name="myTF" id="myTF"></stark:TextTool>
    </s:Application>

Now both of the projects contain an interface file : IModule, with the same code, and an element of the second project (the one that's being loaded) which is an instance of my custom class "TextTool", which extends s:Group and implements IModule:

<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx" width="400"
        xmlns:com="src"
        height="130" creationComplete = "initText()" implements="IModule"></s:Group>

Now as soon as i've loaded the swf, i want to access that TextTool instance which has and id of "myTF" :

//Code in the main class of the main project
    trace(getQualifiedClassName(mySwf.getChildByName('textModule')['myTF']));
    trace(mySwf.getChildByName('textModule')['myTF'] is IModule);
    //output:

    //stark::TextTool
    //false

As i've mentioned above, i have the interface in both projects, same code, it has the same path relative to main classes, and myTF does extend IModule. After the swf is loaded, i get the right element, but i still get false when verifying if it implements IModule. Why?

2
Does 'textModule' show that it implements anything? I wonder if the compiler has renamed one or both to prevent a collision in memory.ethrbunny
'textModule' doesn't implement IModule, what did you expect the compiler to rename?Alex Lucas

2 Answers

0
votes

You're testing Application for implementation

trace(mySwf.getChildByName('textModule') is IModule);

I think you forgot to add ['myTF']

trace(mySwf.getChildByName('textModule')['myTF'] is IModule);
0
votes

You're loading both into different ApplicationDomains, so whichever loads first wins. Try loading them into the same ApplicationDomain.