1 Reply Latest reply on Feb 11, 2011 1:44 AM by _spoboyle

    Using Vars/Const on multiple pages as/mxml

    pur4forlyphe

      Hi,

       

       

      how do you use vars/const's from a flash.as to inside an mxml file - shown below

       

       

       

      DynamicStandardLoader.as

       

       

      ActionScript Code:
      public class DynamicStandardLoader {
             
              // Straight load from the JSON to be used on the settings page
             
              public const _productWidth:Number = (spec["standard"]["product"]["width"]);
              public const _productLength:Number = (spec["standard"]["product"]["length"]);
              public const _productStartPoint:Number = (spec["standard"]["product"]["back_axle_height"]);
             
              public const _leftGap:Number = (spec["track"]["leftRackGap"]);
              public const _rightGap:Number = (spec["track"]["rightRackGap"]);
              public const _pitchLength:Number = (spec["track"]["pitchLength"]);
             
              private var spec:Object;
              private var state:Object;

       

      Into an MXML file with script tags

       

       

      - have ran the - "import DynamicStandardLoader;"

       

       

      settings.mxml

       

       

      ActionScript Code:
      public function loadJSON():void
                  {
                 
                  /*
                  * Product Section
                  */

                     
                      productWidth.text += _productWidth;
                      productLength.text += _productLength;
                      productStartPoint.text += _productStartPoint;
                  
                  /*
                  * Track Section
                  */

                     
                     
                      pitchLength.text += _pitchLength;
                      leftToolRackBox.text += _leftGap;
                      rightToolRackBox.text += _rightGap;
                     
                  }

       

      i would like _pitchLength declared in the DynamicStandardLoader.as to be used in settings.mxml
        • 1. Re: Using Vars/Const on multiple pages as/mxml
          _spoboyle Level 4

          create an instance of DynamicStandardLoader in your mxnml file and reference the consts via that instance.

           

          public function loadJSON():void
                      {

                      var loader:DynamicStandardLoader = new DynamicStandardLoader();
                     
                      /*
                      * Product Section
                      */

                         
                          productWidth.text += loader._productWidth;
                          productLength.text += loader._productLength;
                          productStartPoint.text += loader._productStartPoint;
                      
                      /*
                      * Track Section
                      */

                         
                         
                          pitchLength.text += loader._pitchLength;
                          leftToolRackBox.text += loader._leftGap;
                          rightToolRackBox.text += loader._rightGap;
                         
                      }

          or you could make the conts static if that is approprite and reference the const va the class directly