6 Replies Latest reply on Apr 8, 2009 4:25 AM by hkpadobe

    Variable Scope

    hkpadobe

      I have made a variable Bindable and Public in an MXML file. How do I access this variable in the Root(main MXML) file?

       

      Thanks

        • 1. Re: Variable Scope
          nikos101 Level 2

          Hi welcome to the forum, I hope you find lots of help here and we look forward to your contributions as well

           

          In regards to your question, if its a child of the main file then just

           

          childName.variable

           

          Hope this helps

           

          Best regards

           

          Nikos

           

          • 2. Re: Variable Scope
            hkpadobe Level 1

            Hi Nikos,

             

            I have a 10 separate mxml files that make up my application. As in my question I need to access a variable I have created in one of the 10 files in the main mxml file. I tried your suggestion and got the following error:  1119: Access of possibly undefined property  through a reference with static type Class.

             

            Any clues?

             

            Thanks

            • 3. Re: Variable Scope
              nikos101 Level 2

              You need to use the id of your component, not the name of the class ie

               

              You have a component called Component.

               

              You create that component and give it an id  say     george.

               

              then you do george.property not Component.property

               

               

               

              • 4. Re: Variable Scope
                hkpadobe Level 1

                Nikos,

                 

                Tried that and got the following error: 1120: Access of undefined property myPage2.

                 

                In my main mxml file I have got an Import statement that imports all my Components, so not sure why this error has arisen.

                 

                I am accessing the variable in the main mxml file in an TextInput field as follows:

                 

                <mx:TextInput

                 

                 

                x="825" y="460" id="totVal" width="85" text="{myPage2.totalValue}"/>

                 

                totalValue is a variable I have declared as Bindable and Public in another one of my mxml files, so all I want to do is access this variable in the TextInput field.

                 

                Thanks

                • 5. Re: Variable Scope
                  Michael Borbor Level 4

                  Hi there, as Nikos wrote what you need is to add the component inside your mxml and give the component reference an id: for instance if in your mx:application is like this:

                   

                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                        xmlns:myPage2="*">
                  

                   

                  Then you add any of the components you have to your mxml app file and give the component an id.

                  <myPage2:myComponent id="test" />
                  

                   

                  And finally you can reference the public var

                   

                  <mx:TextInput

                   

                  x="825" y="460" id="totVal" width="85" text="{test.totalValue}"/>

                  • 6. Re: Variable Scope
                    hkpadobe Level 1

                    Michael, Nikos

                     

                    Thanks for your input. I have access to the variable via your sugguestions.