5 Replies Latest reply on Mar 29, 2010 11:19 AM by neptas

    Loading forms

    neptas Level 1

      Hello again,


      I have another question. I have a vbox where I want to show one of three forms, depending of the button the user clicks. Do I need to create states to accomplish this? Without using states I didnt find any other way to do this, but I guess it should be something simple... Any example?


      thank you

        • 1. Re: Loading forms

          You can do it on this way:


          protected function button_clickHandler(event:Event):void{
              switch (event.target.id){                   
                  case 'btnNews':
                      // load form news


                  case 'btnNewsCategory':
                      // load form category


                  case 'btnNewsStatus':
                      // load form status

          <s:Button id="btnNews" label="News" height="20" click="button_clickHandler(event)"/>
          <s:Button id="btnNewsCategory" label="Category" height="20" click="button_clickHandler(event)"/>
          <s:Button id="btnNewsStatus" label="Status" height="20" click="button_clickHandler(event)"/>

          • 2. Re: Loading forms
            Matt Le Fevre Level 4




            the simplest way i can think of doing this would be to manually control the visibility/showLayout properties of the different forms. Here's a quick example with some random components


            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
                        private function showForm2():void
                            box1.visible = false;
                            box1.includeInLayout = false;
                            box2.visible = true;
                            box2.includeInLayout = true;
                        private function showForm1():void
                            box2.visible = false;
                            box2.includeInLayout = false;
                            box1.visible = true;
                            box1.includeInLayout = true;
                <mx:Panel width="600" height="500" layout="absolute">
                    <mx:Box id="box1" width="100%" height="100%" visible="true" includeInLayout="true" horizontalAlign="center">
                        <mx:Label text="This is Form 1" fontSize="25"/>
                        <mx:HRule width="100%"/>
                        <mx:DateField x="426" y="53"/>
                        <mx:ProgressBar x="316" y="228"/>
                        <mx:HRule width="100%"/>
                        <mx:Button click="showForm2()" label="Click to go to form 2"/>
                    <mx:Box id="box2" width="100%" height="100%" visible="false" includeInLayout="false">
                        <mx:Label text="This is Form 2" fontSize="25"/>
                        <mx:HRule width="100%"/>
                        <mx:TextArea text="Blahhhh blahhhhhhhhh blahhhhh"/>
                        <mx:HRule width="100%"/>
                        <mx:Button click="showForm1()" label="Click to go to form 1"/>


            but that's rather messy and not very good practice!




            you could also use a viewStack which would be much better






            depends how simple you want it

            • 3. Re: Loading forms
              neptas Level 1

              hello kubens,


              My problem is to know precisly how to do this: // load form news
              Is there any commando to load a form?


              thank you

              • 4. Re: Loading forms
                neptas Level 1

                hello grizz,


                The second alternative seems to be better. However, and as far as I understand, all the objects in the stack will be in memory right? If so, how flex/adobe reader manage memory? Because I´m seeing myself with a lot of forms in the stack...


                Another thing I would like to know is if there is any best practice to create forms in a more dynamic way. For instance, if you are working with asp or jsp you could have a page for each form, and whenever the form needs to be changed you just need to change it at the server. With flex, it seems you will always need to recompile the swf (ok, we can create an swf file for each form... but it is a little difficult to maintain). Is there examples to accomplish this more dynamically?


                thank you

                • 5. Re: Loading forms
                  kubens Level 2

                  I assume you have FormNews.mxml then you can do it on this way:


                  var formNews:FormNews = new FormNews()

                  PopUpManager.addPopUp(formNews, FlexGlobals.topLevelApplication as DisplayObject, true);