2 Replies Latest reply on Sep 13, 2010 8:03 AM by Gregory Lafrance

    accessing elements of mxml in actionscript

    lalithakumari

      how to access mxml elements from actionscript?

        • 1. Re: accessing elements of mxml in actionscript
          jfb00 Level 3

          Hi,

          Just add and ID to your mxml component and use that name in actionscript like:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="init()">
              <mx:Script>
                  <![CDATA[
                      import mx.controls.Alert;
                     
                      private function init():void{
                          Alert.show(Test.text);
                      }
                  ]]>
              </mx:Script>
              <mx:Label id="Test" text="My Test" />
          </mx:Application>

          I hope this help.

           

          Johnny

          • 2. Re: accessing elements of mxml in actionscript
            Gregory Lafrance Level 6

            And when using components you may need to "chain" your id references.

             

            So if you have an MXML component MyComp, and if that component has a label with an id of myLabel, and if in the main app file you create an instance of the component myCompInst:

             

            trace(myCompInst.myLabel);

             

            If this post answers your question or helps, please mark it as such.


            Greg Lafrance - Flex 2 and 3 ACE certified

            www.ChikaraDev.com

            Flex Training and Support Services