3 Replies Latest reply on Jul 8, 2010 1:57 PM by skider

    Accessing Components From the MXML in the AS

    lkenney2 Level 1

      I have an application. For the visual component of the application, I have created an mxml file:


      <?xml version="1.0" encoding="utf-8"?>
      <ascentify:Main xmlns:fx="http://ns.adobe.com/mxml/2009" 
           width="800" height="600"
           <mx:TabNavigator id="practicePlayer" width="100%" height="100%" creationPolicy="all">
                <modules:Start id="startModule" label="Start" width="100%" height="100%"/>


      'Main' is an AS 3.0 class:


      package com.ascentify {
           import mx.containers.VBox;
           import mx.containers.TabNavigator;
           public class Main extends Application
                     public static var practicePlayer:TabNavigator = new TabNavigator();
                     function Main() {
                          var tab1:VBox = new VBox();


      But the VBox is not added to the TabNavigator. How can I fix this?

        • 1. Re: Accessing Components From the MXML in the AS

          The problem is that the practicePlayer in the Actionscript file and the MXML file are two different things. One is a static variable on the Main class, one is a nonstatic variable on the MXML class. When you're adding tab1 to the practicePlayer, you're adding it to the static variable, which is never added to the display list.


          What is the objective of the Actionscript Main class? Is it to split the Actionscript code out of the MXML? If so, it would be better to include the Actionscript code with a Script tag.


          Is it to create a class of objects that all have a VBox inside a Tab Navigator? If that's the case, you should probably have both the Tab Navigator and the VBox be added to the display list in the parent object.


          Is it for some other reason? If so, what is the reason?

          • 2. Re: Accessing Components From the MXML in the AS
            lkenney2 Level 1

            Hi skider.


            The Main class is over 900 lines long and contains a global variable I need in main. So what I've done now is hollowed out the mainApplication mxml:


            <?xml version="1.0" encoding="utf-8"?>
            <ascentify:Main xmlns:fx="http://ns.adobe.com/mxml/2009" 
                              width="800" height="600" 


            And created the GUI components in the Main class:


            private function createGUIContainer():void
                           playerContainer = new VBox();
                           playerContainer.percentWidth = 100;
                           playerContainer.percentHeight = 100;
                           playerMenu = new MenuBar();
                           playerMenu.percentWidth = 100;
                           playerNavigation = new UnitPlayer();
                           playerNavigation.percentWidth = 100;
                           playerNavigation.percentHeight = 100;
                           playerNavigation.creationPolicy = "all";
                           startModule = new Start();
                           startModule.percentWidth = 100;
                           startModule.percentHeight = 100;
                           startModule.label = "Start";
                           PlayerState.START_MODULE_STATE = playerNavigation.getChildIndex(startModule);


            However, the objects won't load on the stage. Do you know that is?

            • 3. Re: Accessing Components From the MXML in the AS
              skider Level 1

              Just glancing through it, I can't see any reason why the code you've posted shouldn't work. Are you sure it's being called?


              I would advise overriding the createChildren method, and putting the child creation code in there. Flex runs that function automatically when the component is ready to be populated with children. If you do that, make sure to call super.createChildren() somewhere in the function.


              Other than that, I'm not sure what to tell you.