4 Replies Latest reply on Apr 13, 2007 6:18 AM by peterent

    Remembering Checkbox State

    Fuel37 Level 1
      Hey guys,

      I have a checklist type application where you click on a checkbox and it takes you to the next group of questions and so on, then i have built navigation buttons to move back and forth through the questions. What I am running in to now, is that you click on a question (puts a checkmark in the box), takes you to the next screen, click back (shows the previous screen with the checkbox checked as it should be), click on the checkbox again, takes you to the next screen, click back, takes you to the previous screen only now the checkbox is unchecked even though you've already visited.

      Any ideas on how I can set it up so that once you check a checkbox, it stays checked.

      Thanks in advance!
        • 1. Re: Remembering Checkbox State
          Clark_Kent101 Level 1
          Hi,

          Depending on how many questions there are, perhaps you could either assign a value to a bindable global variable or array element when the user checks a checkbox (different value for every checkbox if you want), and then have each checkbox check to see if their corresponding global variable/array element contains their 'checked' value - you can do this using the shorthand if statement within the 'selected' property of each checkbox. That way when you move from one state to another - each 'checked' checkbox will remain checked because of the value of each corresponding global variable/array element for that checkbox not losing scope unless ofcourse the application is shut down by the user.

          I've used this method in another situation that involved different components so I can't guarantee that this will work in your situation but I think it's worth a shot though :).

          Hope that makes sense.

          Cheers.

          - Tony

          • 2. Re: Remembering Checkbox State
            peterent Level 2
            Tony has a good suggestion. But take it a tad farther: create a class for each page of questions with properties for each question/answer. Include in each class a field that says whether or not the page has been visited.

            When you go to page N, get the data for page N and set the checkbox for that page according to the "has visited" field in the data.

            If each page is its own unique MXML file, then you can set up a <mx:Model> for the data in each MXML file. Always include a <hasVisited /> field in the model and tie the CheckBox's selected property to that field:

            <mx:Model id="questions">
            <hasVisited />
            ...
            </mx:Model>

            <mx:CheckBox selected="{questions.hasVisited}" ... />
            • 3. Re: Remembering Checkbox State
              Fuel37 Level 1
              hmmm, interesting.... I'm very new to flex/flash.

              all my code is in one mxml file (this is a very basic checklist).

              so is hasVisited something built into flex? or do I have to write some code behind it too.

              Thanks guys,
              TJ
              • 4. Re: Remembering Checkbox State
                peterent Level 2
                The hasVisited is a variable name I made up. I used it as a member of the <mx:Model>. You'd be better off using separate MXML files. It will make organizing the app and maintaining it a lot easier.