8 Replies Latest reply on Mar 13, 2007 8:57 AM by Gil1

    ow to build a survey app. in Flex 2?

    Gil1 Level 1
      I am developing a survey app. in Flash 8, and I thought - humm... maybe I should try to do it in Flex to start learning it.

      So, I am new to Flex and I don't know how to approach developing the survey app.

      The survey is represented in XML as:

      <Question id="1" type="open ended" nAnswers="1" orientation="vertical" answerReq="0" ramdomize="0" startPage="0">
      <![CDATA[Please detail the procedure you would follow to identify the targets in this kind of terrain]]>
      <BackgroundFile>default</BackgroundFile>
      <Description show="true">Please be as specific as possible</Description>
      <answer type="paragraph" x="35" y="60" w="100" h="78" textArea="1"></answer>
      <objects>
      </objects>
      <notes></notes>
      <QTime></QTime>
      <waitforuser>true</waitforuser>
      </Question>

      The types could be open ended, multiple choice with one or more answers, matrix, etc. In Flash I create Movie Clips for each type at run time and they are rendered in the same page or in a new page depending on the value of startPage (0 or 1).

      I need some guidance on how this can be done in Flex, so I can start playing around. I read about using states, but it does not seem what I need here.

      I discovered how to duplicate containers at run time, using the repeater component.

      However, I still don't know how to tell when to repeat what component...(if type =="multiple choice") use the checkbox kind of thing.

      Also, how I tel the app. to start a new page when needed? I read about states, but how I create states at run time?

      Any ideas are welcome.

      Gilbert
        • 1. Re: ow to build a survey app. in Flex 2?
          peterent Level 2
          Your survey has different pages, right? A good Flex component for that is the ViewStack. It shows one child at a time and you can use effects to transition from one to another.

          As for the content on the pages themselves, I think you want to use ActionScript and not the Repeater. Here's how to create a component in ActionScript. Let's assume you use a ViewStack for your pages. To create a "page" using a VBox:

          var box:VBox = new VBox();
          box.label = "Page "+pageNumber;
          box.percentWidth = 100;
          box.percentHeight = 100;
          stack.addChild(box);

          Now that the box has been created and added to the ViewStack, you could, for example, create a checkbox:

          var component:CheckBox = new CheckBox();
          component.label = "Question 1";
          // add properties
          box.addChild(component);

          I think you're good to go from here
          • 2. Re: ow to build a survey app. in Flex 2?
            Gil1 Level 1
            Peter,

            Thanks. At least this give me some ideas to start experimenting. I guess I have to start trying to think differently when working with Flex. The approach to develop apps. seems very different than using Flash.

            Gilbert
            • 3. Re: ow to build a survey app. in Flex 2?
              peterent Level 2
              If you use ViewStack, make sure you understand creationPolicy. I also encourage you to use data binding whenever possible as it takes the guess work out of when components are ready to receive data. For example, instead of doing this:

              public function setSomeText( s:String ) : void {
              someText.text = s;
              }

              do this:
              [Bindable] private var _someText:String;
              public function setSomeText( s:String ) : void {
              _someText = s;
              }
              ...
              <mx:Text id="someText" text="{_someText}" />

              This is better because the Text control will be changed whenever _someText is changed and you don't have to worry if the Text control is ready to accept updates to its text field or, depending on the ViewStack creationPolicy, if the Text control even exists.
              • 4. Re: ow to build a survey app. in Flex 2?
                Gil1 Level 1
                Thanks. I am reading about ViewStack now, so it is good to take your suggestion into account.

                Gilbert
                • 5. Re: ow to build a survey app. in Flex 2?
                  Gil1 Level 1
                  Peter,

                  I am really lost.. I don't know where to put the code:

                  var box:VBox = new VBox();
                  box.label = "Page "+pageNumber;
                  box.percentWidth = 100;
                  box.percentHeight = 100;
                  stack.addChild(box);

                  and

                  var component:CheckBox = new CheckBox();
                  component.label = "Question 1";
                  // add properties
                  box.addChild(component);

                  Please give me some more guidance.

                  Thanks,

                  Gilbert
                  • 6. Re: ow to build a survey app. in Flex 2?
                    peterent Level 2
                    You put the code in the component where you have the ViewStack. That could be your Application or you could make a component which extends ViewStack and put the code in there.

                    <mx:Application ... >
                    <mx:Script><![CDATA[
                    private function addPage( pageNumber:int ) : void
                    {
                    var box:VBox = new VBox();
                    box.label = "Page "+pageNumber;
                    box.percentWidth = 100;
                    box.percentHeight = 100;
                    stack.addChild(box);
                    }
                    ]]></mx:Script>
                    ...
                    <mx:ViewStack id='stack' ... >

                    That's just a very brief overview. Is that enough to keep you going?
                    • 7. Re: ow to build a survey app. in Flex 2?
                      Gil1 Level 1
                      Thanks, Peter.

                      I will play with that to see how far I can go on my own from here.

                      Probably I will be asking for more help:)

                      Gilbert
                      • 8. Re: ow to build a survey app. in Flex 2?
                        Gil1 Level 1
                        What classes I have to import so Flex can recognize things like

                        new VBox();
                        new new CheckBox();

                        Gilbert