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

    FB4 - custom component problem


      I created new custom component:


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

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



      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"/>




      and added it into the main MXML file into element



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




      via ActionScript:



      var tComponent:tabComponent = new tabComponent();

      tComponent.id = "chatWindow";




      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.



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

          How about something like this:




          You may need to do a cast:




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

          Greg Lafrance - Flex 2 and 3 ACE certified


          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.