PDA

View Full Version : [AS2] Trouble with my combo boxes (but not with the combo boxes themselves)


Vagabond
02-27-2009, 02:54 PM
// dynamic combo boxes
// make new date object
var myDate:Date = new Date();

// create dobMonth arrays
var monthArray30:Array = new Array(4,6,9,11);
var monthArray31:Array = new Array(1,3,5,7,8,10,12);

// this is broken... it still won't use 30 or 31
// create a listener for dobMonth and dobYear
// when these are changed, repopulate dobDate
var cbListener:Object = new Object();
cbListener.change = function(evt_obj:Object):Void {

// set monthSelected and yearSelected
var monthSelected:Object = dobMonth.selectedItem;
var yearSelected:Object = dobYear.selectedItem;
trace(monthSelected.data);
trace(yearSelected.data);

// if "monthSelected" is in the array "monthArray30" (4,6,9,11)
if(monthArray30.in_array(monthSelected.data)){

// set popDays to 30
var popDays:Number = 30;

// else, if "monthSelected" is in the array "monthArray31" (1,3,5,7,8,10,12)
} else if(monthArray31.in_array(monthSelected.data)){

// set popDays to 31
var popDays:Number = 31;

// else, if "monthSelected" is 2 (february)
} else if(monthSelected.data = 2){

// determine if yearSelected is a leap year
// if "yearSelected" is divisible by 4, AND NOT 100, or divisible by 400
if(((yearSelected.data % 4 == 0) && (yearSelected.data % 100 != 0)) || (yearSelected.data % 400 == 0)){

// set popDays to 29 (leap year)
var popDays:Number = 29;

// else, if "yearSelected" is NOT a leap year
} else {

// set popDays to 28
var popDays:Number = 28;

} // end if((yearSelected % 4 == 0) && (yearSelected % 100 != 0)) || (yearSelected % 400 == 0)

} // end if(monthArray30.in_array(monthSelected))

// populate dobDate with popDays
for(var i:Number = 1; i<=popDays; i++){

dobDate.addItem({data:i, label:i});

} // end for(var i:Number = 0; i<30; i++)

};

// apply listener to dobMonth and Year
dobMonth.addEventListener("change", cbListener);
dobYear.addEventListener("change", cbListener);

// create myYears, starting with this year
var myYears:Number = myDate.getFullYear();

// populate dobYear with deincrementing loop,
// starting with the current year and going back 80 years
for(var i:Number = myYears; i>(myYears-80); i--){

// populate dobYear data and label with i
dobYear.addItem({data:i, label:i});

} // end for(var i:Number=currentYear; i>(currentYear-80); i--)

this is the action script I have running my combo boxes. Basically, it's a form to select the user's birth day. The year box (dobYear) populates just fine, and when I select a month (dobMonth), the date (dobDate) populates, it's just not with the correct number of days.

The traces I ran on the monthSelected and yearSelected variables confirm that it is returning the appropriate numbers, but for some reason the date (dobDate) will only ever populate with either 28 or 29 days. So there must be something wrong with either my arrays, or the conditions in my if,then statement, but I just can't figure out what

What am I doing wrong?

if you need, I've attached the FLA in a zip file. The code in question appears on the main time line (while I work out the bugs), in the second frame.

when viewing, select the "Sign Up" from the bottom right hand side of the clip board to see the form.

Vagabond
02-28-2009, 11:49 AM
the problem's gotta be in my if,then statements where I use the in_array method to figure out how many days to print, but i can't pin-point where my error is...

Vagabond
02-28-2009, 11:56 AM
also, damnit... I was really hoping this thread wouldn't get moved into the components forum -_- the problem isn't with the components themselves, I just happen to be -using- components when I messed up my code.

Vagabond
03-04-2009, 04:02 AM
Turns out I was missing an = in the comparrison

when I compared the selected data to February (2), I used = instead of == to compare. so the script read it as an assignment, and in the comparison, it became always true.

Combo Boxes: A New Dilemma (http://www.actionscript.org/forums/showthread.php3?p=852927#post852927)

Now I have a new problem =_=