0

I'm fairly new to Flex and am having an issue where I have a main Flex program (let's called it "Parent.swf") attempting to load another Flex application (Child.swf) via the SWFLoader class/component. Environment is Flex 4.6 on FlashDevelop.

The call appears to work correctly (i.e. no IO or sandbox errors are returned), only that it seems to reload the "Parent.swf" into the SWFLoader instead of the "Child.swf".

For example, I have the Parent.swf containing:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           initialize="doStartup()" 
           width="1024" height="768">

...

<fx:Script>

    <![CDATA[

        private function doStartup():void
        {
            trace("STARTING UP!");
        }

        ....

    ]]>

</fx:Script>

<mx:VBox top="10" left="10" width="100%" horizontalAlign="center">
    <mx:Label text="I'M A LOADER!" />
</mx:VBox>
<mx:VBox top="10" left="10" width="100%" horizontalAlign="center">
    <mx:SWFLoader 
                    id="pluginLoader"
                    source="plugins/Child.swf" 

                    autoLoad="true" 
                    height="400" width="400" 
                    complete="onPluginLoaded(event);" 
                    ioError="onPluginLoadError(event);" 
                    securityError="onPluginSecurityError(event);" 

                    httpStatus="onHttpStatus(event);"
                    init="onInit(event);"
                    open="onOpen(event);"
                    progress="onProgress(event);"
                    unload="onUnload(event);"
                    />
</mx:VBox>

....

The child swf contains:

....
<mx:Label text="I'M A PLUGIN!" />
....

The trace above (i.e. "STARTING UP!") is repeated on the load of Child.swf, followed by another attempt to load Child.swf which fails because the working directory for the call is now in the "plugins" directory. So it seems to know the file exists and load it, but somehow swaps in Parent.swf over the top of it. Note that if I execute Child.swf directly, I'm able to verify that it is what I expect it to be (i.e. a flex app with a single label saying "I'M A PLUGIN!").

I've also tried various other approaches such as instantiating a SWFLoader via code but the same issue occurs. I even tried to switch to Modules but had the same behaviour there too. It fails whether run locally or run via a web server.

Does anyone have any idea how this could occur? Is there some way that the main.mxml of Parent.swf is overriding Child.swf? (Sorry for the essay)

2 Answers2

0

I need the full code to discovery. But I can suggest two ideas:

  1. Check your onPluginLoaded function, it can be called by Parent instead of the Child

  2. Check if you don't have any class or object name repeated that can generated a cross-reference. For example, both Parent and Child use MyScrollbarClass. As this class was firstly loaded by Parent, it will create a new name when load in Child, like MyScrollbarClass_1

Harrison
  • 195
  • 1
  • 2
  • 9
  • Gaah, I feel like such an idiot. It was sort of related to your second point there... both applications used main as the mxml filename. If I change one of them to a different name then it all works fine! Cheers Harrison. – user4667964 Mar 18 '15 at 00:31
0

mxml file must be named differently in loaded applications