CheckBox component - using as a toogle
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Ned,
This is what I have so far:
On the first frame of the quiz:
function(){return A.apply(null,[this].concat($A(arguments)))} flag1.addEventListener(Event.CHANGE, checkTheBox);
function checkTheBox(e:Event):void{
if(e.currentTarget.selected){
flaggedQuestion.push({label:currentLabel, data:currentLabel});
} else {
flaggedQuestion.splice({label:currentLabel, data:currentLabel});
}
}
on any subsequent pages:
flag2.addEventListener(Event.CHANGE, checkTheBox);
At the review section:
function(){return A.apply(null,[this].concat($A(arguments)))} //Data for questionList comboBox
flaggedList.visible = true
flaggedList.dataProvider = new DataProvider(flaggedQuestion);
flaggedList.addEventListener(Event.CHANGE, changeHandler);
function changeHandler(event:Event):void
{
gotoAndStop(flaggedList.selectedItem.data);
}
The comboBox IS displaying the correct targets and allows for navigation to the specific page. When I arrive at the page, the chech box defaults back to uncheck... This allows for the user to re-check in which case messes up the "flaggedQuestion" array... I tried adding "e.currentTraget.enable = false" when the user clicks on the checkBox, but when the user returns to this page, it is uncheck and enabled again.
Rafa.
Copy link to clipboard
Copied
This goes back to my first response. In each frame where you have a checkbox you need to test if the currentLabel is in the array and set the checbox to be selected if it is found in the array. If you weren't assigning objects into the array you could use the indexOf() method to check for the currentLabel directly. But since you are storing objects in the array I believe you will have to create a function that loops thru the array and tests for the currentLAbel being assigned as the label of one of the objects. You could have each frame with a checkbox call that function, passing the currentLabel as an argument to the function.
Copy link to clipboard
Copied
Ned,
I understand what you are saying, I will look into your last suggestion. Again, thank you for your help.
Rafa.

