2 Replies Latest reply on Nov 26, 2009 11:08 PM by Flex harUI

    Error in the example of "Adobe Flex 3 Developer Guide"


      An error occured while I was trying a example in the book 《Adobe Flex 3 Developer Guide》.

      In page 275 of that book, the small title is "Interacting with a loaded Flex application".


      I compile out a swf file from the below code as the book said.


      <?xml version="1.0"?>
      <!-- controls\swfloader\FlexApp.mxml -->
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
      height="200" width="200">
      public var varOne:String = "This is a public variable.";
      public function setVarOne(newText:String):void {
      <mx:Label id="lblOne" text="I am here."/>
      <mx:Label text="{varOne}"/>
      <mx:Button label="Nested Button" click="setVarOne('Nested button pressed.');"/>


      Then I try following code according the book.


      <?xml version="1.0"?>
      <!-- controls\swfloader\SWFLoaderInteract.mxml -->
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
         import mx.managers.SystemManager;
         import mx.controls.Label;
         public var loadedSM:SystemManager;
         // Initialize variables with information from
         // the loaded application.
         private function initNestedAppProps():void {
          loadedSM = SystemManager(myLoader.content);
         // Update the Label control in the outer application
         // from the Label control in the loaded application.
         public function updateLabel():void {
         // Write to the Label control in the loaded application.
         public function updateNestedLabels():void {
          loadedSM.application["lblOne"].text = "I was just updated.";
          loadedSM.application["varOne"] = "I was just updated.";
         // Write to the varOne variable in the loaded application
         // using the setVarOne() method of the loaded application.
         public function updateNestedVarOne():void {
          FlexApp(loadedSM.application).setVarOne("Updated varOne!");
      <mx:Label id="lbl"/>
      <mx:SWFLoader id="myLoader" width="300" source="FlexApp.swf" creationComplete="initNestedAppProps();"/>
      <mx:Button label="Update Label Control in Outer Application" click="updateLabel();"/>
      <mx:Button label="Update Nested Controls" click="updateNestedLabels();"/>
      <mx:Button label="Update Nexted varOne" click="updateNestedVarOne();"/>


      But I got a compiling error at secentence: FlexApp(loadedSM.application).setVarOne("Updated varOne!"), which saying that the FlexApp may be not defined.

      And if I comment that secentence, I would get a runtime error, if I push any button.

      Need your help.