2 Replies Latest reply on Jan 10, 2010 10:19 PM by Flex harUI

    Accessing module's function via its parent

    andreamesser

      Hi,

       

      I have a module I inserted with moduleLoader and inside the module I'm trying to have one its functions run but I keep getting an undefined error.

       

      How can I access a function in a module from the parent. I have tried a couple different method and have even gotten to the point where no problem is identified until runtime.

       

      Below I have included the code for the application.

       

      Thanks in advance for any help you can provide.

       

      Justin

       

       

      Application Code below:

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]"

      backgroundGradientColors="

      [#008C69, #E3E0E0]" xmlns:comps="components.*" applicationComplete="init()">

       

       

       

       

      <mx:ApplicationControlBar dock="true" fillAlphas="[1.0, 1.0]" fillColors="[#E3E0E0, #E3E0E0]" themeColor="#008C69">

       

       

      <mx:MenuBar id="myMenu" dataProvider="{xLocations}" labelField="@label" itemClick="itemClickHandler(event)" fillAlphas="[1.0, 1.0]" fillColors="[#E3E0E0, #E3E0E0]" color="#3D3D3D">

       

       

       

      </mx:MenuBar>

       

       

       

      </mx:ApplicationControlBar>

       

       

       

       

       

       

      <comps:MyComponent y="525" x="407">

       

       

       

      </comps:MyComponent>

       

       

       

      <mx:Script>

      <![CDATA[

       

       

      import mx.modules.Module;

       

      import mx.events.MenuEvent;

       

      import mx.validators.ValidationResult;

       

      import mx.rpc.events.ResultEvent;

       

      import mx.rpc.events.FaultEvent;

       

      import mx.controls.Alert;

       

      import flash.events.Event;

       

      import flash.net.URLLoader;

       

      import flash.net.URLRequest;

       

      import mx.modules.ModuleLoader;

       

      import mx.modules.ModuleManager;

       

      import mx.modules.IModuleInfo;

       

      import modules.survey;

      [

      Bindable]

       

      private var myModule:survey;

       

      [

      Bindable]

       

      private var xLocations:XMLList;

       

      [

      Bindable]

       

      private var a:String;

       

       

      private function init():void {

      xmlService.send();

      xmlMenu.send();

      }

       

      private function loaderInit():void

      {

       

      myModule.treeMenu.send();

       

      }

       

       

      private function getList():void {

       

      }

       

       

      public function loadXML():void

      {

       

       

      //var xmlLoader:URLLoader = new URLLoader();

       

       

      //xmlLoader.load(new URLRequest("http://www.visualdemocracy.com/xml.php"));

       

       

      //xmlLoader.addEventListener(Event.COMPLETE, handleLoad);

      }

       

       

       

      public function handleLoad(event:Event):void

      {

       

      }

       

       

       

      // Result handler - gets called after RSS is loaded.

       

       

      private function resultHandler(event:ResultEvent):void

      {

       

        

      xLocations = event.result.section;

      }

       

       

       

      // Fault handler - displays the error.

       

       

      private function faultHandler(event:FaultEvent):void

      {

      Alert.show(

       

      "Data errors");

      }

       

      // Data verification

       

       

      private function correctHandler(event:FaultEvent):void

      {

      Alert.show(

       

      "The data matches");

      }

       

       

      private function itemClickHandler(event:MenuEvent):void

      {

       

      var selectedMenu:XML = event.item as XML;

       

      trace("You selected" + selectedMenu.@label);

      }

       

       

      public function createModule(m:ModuleLoader, s:String):void {

       

      if (!m.url)

      {

      m.url = s;

       

      return;

      }

      m.loadModule();

      }

       

       

      public function removeModule(m:ModuleLoader):void {

      m.unloadModule();

      }

      ]]>

       

      </mx:Script>

       

       

      <mx:HTTPService id="xmlService"

      url="

      data/invoices.xml"

      result="resultHandler(event)"

      resultFormat="

      e4x"/>

       

       

      <mx:HTTPService id="xmlMenu"

      url="

      data/menu.xml"

      result="resultHandler(event)"

      resultFormat="

      e4x"/>

       

       

       

      <mx:Button label="Change Data" x="435" y="555"/>

       

      <mx:Button label="Get List" click="getList()" x="451" y="525"/>

       

       

      <mx:ModuleLoader id="mainLoader" x="10" y="10" url="modules/survey.swf" width="800" height="500" ready="loaderInit()">

       

      </mx:ModuleLoader>

       

       

      <mx:Canvas x="10" y="417" width="400" height="100" backgroundColor="#FFFFFF" cornerRadius="5" borderColor="#FFFFFF">

       

      </mx:Canvas>

       

      </mx:Application>