0 Replies Latest reply on Oct 12, 2009 4:13 PM by SiHoop

    Linking problem

    SiHoop Level 1

      I run into the problem below quite often and I'm hoping that someone can tell me the correct way to code the solution.

       

      I begin with a ViewStack for navigation, then I use the class TestButtons to add checkboxes that allow me to navigate. Finally, I use the class InstructorView as a destination when I click on a check box.

      My problem is as follows: The file TestButtons.mxml uses Application.application as a way to navigate back to the root file. I hate doing this as I know that it's going to eventually get me into trouble, especially when I place my files into a larger project. I'm sure there must be a better way to navigate or perhaps to structure my files so I don't have to use the Application.application work around. Can anyone suggest a better way?

      Many thanks for your time.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*" layout="vertical" width="100%" height="100%"  creationComplete="init()">
      <mx:Script>
          <![CDATA[
              private function init():void{
                  var testButtons:TestButtons=new TestButtons
                  testButtons.testsArray=["a","s","d"]
                  mainMenu.addChild(testButtons)
              }
          ]]>
      </mx:Script>   
          <mx:Panel   width="30%" height="30%" >        
              <mx:ViewStack   id="viewStack" width="100%" height="100%" >
                  <mx:VBox id="mainMenu" >
                  </mx:VBox>
                  <mx:VBox id="instructor">
                      <local:InstructorView/>
                  </mx:VBox>
              </mx:ViewStack >
          </mx:Panel>
               <mx:HBox>
                   <mx:Button label="Main Menu" click="viewStack.selectedChild=mainMenu;"/>
               </mx:HBox>
      </mx:Application>

       

      TestButtons.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="80%" height="100%">
      <mx:Style source="styles/styleSheet.css" />
      <mx:Script>
          <![CDATA[
          import mx.core.Application;
          import mx.controls.CheckBox;
          public var _testsArray:Array=[];
          public function set testsArray(value:Array):void {
              _testsArray=value;
              makeCheckbox(_testsArray)
          }
         public function makeCheckbox(_testsArray:Array):void {
              for(var i:int=0;i<_testsArray.length;i++){
                  var s:CheckBox=new CheckBox
                  this.addChild(s)
                  this.y+=30
                  s.addEventListener(MouseEvent.CLICK,checkButton)
              }
          }
          public function checkButton(e:Event):void {
              Application.application.viewStack.selectedChild=Application.application.instructor
          }
          ]]>
      </mx:Script>
      </mx:VBox>

       

      InstructorView.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"  creationComplete="init()" width="100%" height="100%">
      <mx:Style source="styles/styleSheet.css" />
          <mx:Script>   
              <![CDATA[

       

      [Bindable] private var _separatedWords:Array=[];
      [Bindable] private var studentsContent:String//students data from the database

       

      private function init():void{
          text.text="Some text"
      }
              ]]>
          </mx:Script>
          <mx:Text  id="text" x="100" y="100" />
      </mx:Canvas>