So, I’m building this vote app for a client. There are 6 items to choose from, but the user can only select 3 at a time. All of the “items” are Component CheckBox items.
My problem is, once the user clicks 3 and then say wants to “change” a vote and they check a 4th (regardless of unchecking one of the previous 3) one of the previous three buttons does not uncheck and the vote just keeps on checking checkboxes. Confusing as hell, I know. Here is code to perhaps shed some light:
var clicked:String;
var choice1:String;
var choice2:String;
var choice3:String;
var choice4:String;
//var previousChoice:String;
var clickCount:Number;
clickCount = 0;
// Idea is to fill the choices above, then as new one is chosen it moves from 1 to 2 to 3, if a new one beyond 3 is added
// the first one chosen which at this point would be the third would move from 3rd to 4th and then it would clear/uncheck
// and not be chosen.
function newChoice():Void {
if(clickCount ==1) {
choice1 = clicked;
clicked = "";
trace(choice1);
} else if (clickCount ==2) {
choice2 = choice1;
choice1 = clicked;
clicked ="";
//choice1 = choice2;
trace("Choice 2 = "+choice2);
trace("Choice 1 = "+choice1);
} else if(clickCount==3) {
choice3=choice2;
choice2=choice1;
choice1=clicked;
clicked ="";
trace("Choice 3 = "+choice3);
trace("Choice 2 = "+choice2);
trace("Choice 1 = "+choice1);
} else {
// this is working, but the unchecking of the first selection or anything beyond 3 total is not working.
choice4=choice3;
choice3=choice2;
choice2=choice1;
choice1=clicked;
clicked ="";
trace("Choice 4 = "+choice4);
trace("Choice 3 = "+choice3);
trace("Choice 2 = "+choice2);
trace("Choice 1 = "+choice1);
// not recognizing the code below as I think it needs to be in the oListener below, but not sure.
//choice4.selected = false;
}
};
var oListener:Object = new Object();
oListener.click = function(oEvent:Object):Void {
//trace(oEvent.target._name + " was just clicked");
clicked = (oEvent.target._name);
clickCount++;
trace(clickCount);
newChoice();
};
GRTS001.addEventListener("click", oListener);
GRTS002.addEventListener("click", oListener);
GRTS003.addEventListener("click", oListener);
GRTS004.addEventListener("click", oListener);
GRTS005.addEventListener("click", oListener);
GRTS006.addEventListener("click", oListener);
stop();
Any help would be greatly appreciated. I know, all this would probably be easier in AS3, right, but unfortunately it’s in AS2.