Skip to main content
rafa@mediatech
Inspiring
March 16, 2010
Question

CheckBox component - using as a toogle

  • March 16, 2010
  • 1 reply
  • 837 views

Hi everyone,

I have a project with 100 pages or so. Each of this pages will have a label name. I am trying to create a toogle button that will ad the frane name to an array by using "currentLabel". If the user unchecks the box, then remove "curentLabel" from the array. At the end, there will be a "review" section where the items on the array will show in a comboBox so that the user can navigate to each of these pages.

I already have the combo bit working:


flaggedList.dataProvider = new DataProvider(flaggedQuestion);
flaggedList.addEventListener(Event.CHANGE, changeHandler);

function changeHandler(event:Event):void
{
  gotoAndStop(flaggedList.selectedItem.data);
}

I tested it by using a button that added the "currentLabel" to the "flaggedQuestion" array. But is the user clicks on the button more than once on the same page, it keeps adding the same label (as it should). Thats why I figure using a checkBox component that the user can check and uncheck would be an ideal solution. The problem I have with checkboxes, is that it is not keeping the "check" on the box is the user navigates back and forward thru the sections...

Any ideas?

Thank you in advance,

Rafa.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
March 16, 2010

If you wanted to use the button approach, you could have the button test to see if the curentLabel is already in the array using the array.indexOf() method.  That way you can avoid duplication of it in the array.

I believe you can take a similar approach for checkboxes and at each frame test to see if the currentLabel is in the array already and either check or not check the checkbox as a result of that test.

rafa@mediatech
Inspiring
March 16, 2010

Ned,

Like always, thank you for putting me on the right track. So how do I use the checkBox component to add/take items in the array? I have found some samples online, but they are basically a "one time use" of the check box. In my case, the user can (and probably will) navigate away, come back, check and uncheck the box.

thank you,

Rafa.

Ned Murphy
Legend
March 16, 2010

You'll need to look into the Array class methods to get a handle on which you need to use for adding and removing items from an array.  But as far as the checkbox goes, it can be a simple matter of testing its selected property whenever a CHANGE event is encountered...

cb.addEventListener(Event.CHANGE, checkTheBox);

function checkTheBox(e:Event):void{
      if(e.currentTarget.selected){
            // push() the currentLabel into the array
      } else {
            // splice() the currentLabel from the array
      }
}

You could probably use the same event handler function in all cases, which is why I show e.currentTarget being used.