1 Reply Latest reply on Jan 14, 2011 1:15 PM by Flex harUI

    Question mx:Canvas to s:Group migration

    Mat_D

      Hello,

       

      I'm currently migrating a Flex 3 project to Flex 4. Unfortunately I don't quiet get the correspondence between

       

      mx:Canvas and s:BorderContainer that is recommended by the API Doc.

       

      Here are my Flex 3 and 4 Version. I'm trying to get a reference of myButton in the class called GUIManager by passing the reference of myContainer. This works perfectly when using mx:Canvas (in FX3) but now in FX4 the only solution I've found
      is to use a s:Group. Using a s:BorderContainer will throw errors in the GUIManager because the "path" to myButton is different or null.

       

      Isn't s:BorderContainer also derivated from DisplayObjectContainer ?

      What would be your correct solution to correctly migrate mx:Canvas ?

       

      Flex 3 - Version

      -----------------------

      In my .mxml
      
      <mx:Script>
      var guiManager:GUIManager = new GUIManager(myContainer);
      </mx:Script>
      <mx:Canvas id="myContainer" width="273" height="263" x="29" y="13">
          <s:Button id="myButton" x="10" y="22" label="Hello" name="myButton" enabled="true">        
          </s:Button>
      </mx:Canvas>
      
      In GUIManager.as
      
      public function GUIManager(aDisplay:DisplayObjectContainer)
      {           
          trace(aDisplay.getChildByName("myButton").y); // Works 
      }
      

       

      Flex 4 - Version
      -----------------------

       

      In my .mxml
      
      <fx:Script>
      var guiManager:GUIManager = new GUIManager(myContainer);
      </fx:Script>
      <s:Group id="myContainer" width="273" height="263" x="29" y="13">
          <s:Button id="myButton" x="10" y="22" label="Hello" name="myButton" enabled="true">        
          </s:Button>
      </s:Group>
      
      In GUIManager.as
      
      public function GUIManager(aDisplay:DisplayObjectContainer)
      {    
          trace(aDisplay.getChildByName("myButton").y); // Crashes if I use something else than a s:Group
      }