4 Replies Latest reply on Apr 3, 2010 12:23 AM by Shongrunden

    FB4 - custom component problem

    HakkaMc

      I created new custom component:

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:NavigatorContent  xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="library://ns.adobe.com/flex/spark"

      xmlns:mx="library://ns.adobe.com/flex/mx"

      label="universal" width="503" height="570"

      >

      <s:TextArea name="ta" x="10" y="11" editable="false" width="483" height="353"/>

      <s:TextArea name="textToSend" x="11" y="398" width="482" height="164" editable="true"/>

      <s:Button x="327" y="370" label="Send message" id="sendButton"/>

      </s:NavigatorContent>

       

       

      and added it into the main MXML file into element

       

       

      <mx:TabNavigator id="myTabNavigator" x="442" y="24" width="503" height="570">

      </mx:TabNavigator>

       

       

      via ActionScript:

       

       

      var tComponent:tabComponent = new tabComponent();

      tComponent.id = "chatWindow";

      myTabNavigator.addElement(tComponent);

       

       

      But now I want to access the button with id="sendButton" from script section in the main MXML. I tried something like

      this["sendButton"] or tComponent.sendButton

      but having no luck.

       

      Is there a way how to access the element packed in custom component? Simply...I need something like document.getElementById("sendButton") and then add a click event listener.

       

      Thanks...

        • 1. Re: FB4 - custom component problem
          Gregory Lafrance Level 6

          How about something like this:

           

          myTabNavigator.getChildAt(0).sendButton

           

          You may need to do a cast:

           

          tabComponent(myTabNavigator.getChildAt(0)).sendButton

           

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


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          1 person found this helpful
          • 2. Re: FB4 - custom component problem
            HakkaMc Level 1

            Thanks a lot!

             

            The first type of access you wrote is incorrect but the second works!

             

            Once again thanks a lot :-)

            • 3. Re: FB4 - custom component problem
              HakkaMc Level 1

              The access works only if the added tab is selected or was once selected. Otherwise it looks like the button does not exist.

               

              AS code:

              <component creation>

              <adding component>

              Alert.show(tabComponent(myTabNavigator.getChildAt(myTabNavigator.numChildren-1))["sendButt on"]==null?"yes\n":"no\n"); //shows no

               

              <component creation>

              <adding component>

               

              Alert.show(tabComponent(myTabNavigator.getChildAt(myTabNavigator.numChildren-1))["sendButt on"]==null?"yes\n":"no\n"); //show yes

               

               

               

              But if I chose the second tab and do

               

              Alert.show(tabComponent(myTabNavigator.getChildAt(myTabNavigator.numChildren-1))["sendButt on"]==null?"yes\n":"no\n");

               

              it shows "no".

              • 4. Re: FB4 - custom component problem
                Shongrunden Adobe Employee

                Set creationPolicy="immediate" on the TabNavigator.  This will mean the contents of each tab are created at startup rather than when the tab is first visited.