5 Replies Latest reply on Aug 22, 2009 8:42 PM by camranhameed

    Show a custom component on button click in a view stack`

    camranhameed

      Hello folks

       

      I have a view stack in which i have some custom components.

       

      Now there is one custom component in which there is one button. On the button click, i want to show another custom component but i dont know how to do it. Should i write the inline mxml click event in custom component?? If yes then how??

       

      Currently i am doing it as

       

      click="{customcomponent}"

        • 1. Re: Show a custom component on button click in a view stack`
          alex-86

          hi, why dont you use the .addChild("id");

           

          for example, give the component that you want an id. and in the other component

           

          do something like this:

           

          I am assuming that in the component that you are adding you have a vbox or something.

           

          <custom id="cus1" />

           

          vbox.addChild(cus1);

          • 2. Re: Show a custom component on button click in a view stack`
            camranhameed Level 1

            The thing is that i want to show the custom component on button click. Its not that i want to show the cusotm component on application statup.

            • 3. Re: Show a custom component on button click in a view stack`w
              alex-86 Level 1

              well, you could create it, put it where you want in your application and make it visible = false, and when you click just make it visible = true

               

              how about that?

              • 4. Re: Show a custom component on button click in a view stack`
                Gregory Lafrance Level 6

                As you know, ViewStack  has containers, lilke VBox for its views.

                 

                Assuming one of your views VBox has an id of myVBox, and that VBox has the Button that when clicked will display the component, just have the component in the view already, but you can make it invisible with visible=false and includeInLayout=false, and then upon button click set those two variables to true.

                 

                You will probably want a show handler for the view VBox to make those properties false each time that view is displayed.

                 

                Here is some simple sample code.

                 

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

                 

                ---------- MySimpleComponent.mxml ----------

                <?xml version="1.0" encoding="utf-8"?>
                <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
                  width="100%" height="100%" horizontalAlign="center">
                  <mx:Label text="My Custom Component"/>
                </mx:VBox>

                 

                 

                ---------- MainApp.mxml  ----------

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                  xmlns:comp="*" horizontalAlign="center" verticalAlign="middle">
                  <mx:Script>
                    <![CDATA[
                     
                    ]]>
                  </mx:Script>
                  <mx:LinkBar dataProvider="{vs}"/>
                  <mx:ViewStack id="vs" width="100%" height="100%">
                    <mx:VBox label="view1" width="100%" height="100%"
                      horizontalAlign="center">
                      <mx:Label text="View One"/>
                    </mx:VBox>
                    <mx:VBox label="view2"  width="100%" height="100%"
                      show="myComp.visible=false;myComp.includeInLayout=true;"
                      horizontalAlign="center">
                      <mx:Label text="View Two"/>
                      <mx:Button label="Make myComp Visible" click="myComp.visible=true;myComp.includeInLayout=true;"/>
                      <comp:MySimpleComponent id="myComp" visible="false" includeInLayout="false"/>
                    </mx:VBox>
                  </mx:ViewStack>
                </mx:Application>

                • 5. Re: Show a custom component on button click in a view stack`
                  camranhameed Level 1

                  I tried to do what you suggested but when i write

                   

                   

                  <VBox id="one"

                  show="mycomponents.CustomComp1.visible=false"

                   

                  then it gives me this error

                   


                  1119: Access of possibly undefined property visible through a reference with static type Class.

                   

                   

                  P.S: When i change something in the code and relaunch the application, it doesnt show the updated application. I "clean" the project but no use. If i go and see the .swf file, it is updated, but i dont know why the page doesnt gets updated...