Vagabond
03-04-2009, 04:00 AM
I figure a simple problem out, and a bigger one takes it's place. Allow me to start from the top.
I'm creating a user registration form in flash and I want to use combo boxes for the users to enter their date of birth and location.
Now, in order to protect from users from doing silly things like entering February 31st as their birthday, I'm going to populate the combo boxes through actionscript depending on the month and year the user selected.
If the user selects a month with 31 days in it, I want the date box to have 31 days in it. If they select a month with only 30 days in it, I want the date box to only have 30 days to choose from, and if the user selects February, I want only 28 days to appear, unless the user also selected a leap year.
Sounds easy enough. I fixed the problem of the boxes only populating as if the user selected February (I used = instead of == in the comparison), but now there's an even worse bug. When I run the script and try to select either a month or a year, the program crashes and tells me, "A script in this movie is causing Flash Player to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"
Given 3 combo boxes (dobMonth, dobDate, dobYear), here's the script in question:
10 // dynamic combo boxes
11 // make new date object
12 var myDate:Date = new Date();
13
14 // create dobMonth arrays
15 // if the month selected is April(4), June(6), September(9), or November(11)
16 var monthArray30:Array = new Array(4,6,9,11);
17 // if the month selected is January(1), March(3), May(5), July(7), August(8), October(10), or December(12)
18 var monthArray31:Array = new Array(1,3,5,7,8,10,12);
19
20 // this is broken... it still won't use 30 or 31
21 // create a listener for dobMonth and dobYear
22 // when these are changed, repopulate dobDate
23 var cbListener:Object = new Object();
24 cbListener.change = function(evt_obj:Object):Void {
25
26 // set monthSelected and yearSelected
27 var monthSelected:Object = dobMonth.selectedItem;
28 var yearSelected:Object = dobYear.selectedItem;
29 trace(monthSelected.data);
30 trace(yearSelected.data);
31
32 // if "monthSelected" is in the array "monthArray30" (4,6,9,11)
33 if(monthArray30.in_array(monthSelected.data)){
34
35 // set popDays to 30
36 var popDays:Number = 30;
37
38 // else, if "monthSelected" is in the array "monthArray31" (1,3,5,7,8,10,12)
39 } else if(monthArray31.in_array(monthSelected.data)){
40
41 // set popDays to 31
42 var popDays:Number = 31;
43
44 // else, if "monthSelected" is 2 (february)
45 } else if(monthSelected.data == "2"){
46
47 // determine if yearSelected is a leap year
48 // if "yearSelected" is divisible by 4, AND NOT 100, or divisible by 400
49 if(((yearSelected.data % 4 == 0) && (yearSelected.data % 100 != 0)) || (yearSelected.data % 400 == 0)){
50
51 // set popDays to 29 (leap year)
52 var popDays:Number = 29;
53
54 // else, if "yearSelected" is NOT a leap year
55 } else {
56
57 // set popDays to 28
58 var popDays:Number = 28;
59
60 } // end if((yearSelected % 4 == 0) && (yearSelected % 100 != 0)) || (yearSelected % 400 == 0)
61
62 } // end if(monthArray30.in_array(monthSelected))
63
64 // populate dobDate with popDays
65 for(var i:Number = 1; i<=popDays; i++){
66
67 dobDate.addItem({data:i, label:i});
68
69 } // end for(var i:Number = 0; i<30; i++)
70
71 };
72
73 // apply listener to dobMonth and Year
74 dobMonth.addEventListener("change", cbListener);
75 dobYear.addEventListener("change", cbListener);
76
77 // create myYears, starting with this year
78 var myYears:Number = myDate.getFullYear();
79
80 // populate dobYear with deincrementing loop,
81 // starting with the current year and going back 80 years
82 for(var i:Number = myYears; i>(myYears-80); i--){
83
84 // populate dobYear data and label with i
85 dobYear.addItem({data:i, label:i});
86
87 } // end for(var i:Number=currentYear; i>(currentYear-80); i--)
What on Earth am I doing wrong? Is addItem an improper method for what I'm doing? If so, what would be better suited for this task?
I'm creating a user registration form in flash and I want to use combo boxes for the users to enter their date of birth and location.
Now, in order to protect from users from doing silly things like entering February 31st as their birthday, I'm going to populate the combo boxes through actionscript depending on the month and year the user selected.
If the user selects a month with 31 days in it, I want the date box to have 31 days in it. If they select a month with only 30 days in it, I want the date box to only have 30 days to choose from, and if the user selects February, I want only 28 days to appear, unless the user also selected a leap year.
Sounds easy enough. I fixed the problem of the boxes only populating as if the user selected February (I used = instead of == in the comparison), but now there's an even worse bug. When I run the script and try to select either a month or a year, the program crashes and tells me, "A script in this movie is causing Flash Player to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"
Given 3 combo boxes (dobMonth, dobDate, dobYear), here's the script in question:
10 // dynamic combo boxes
11 // make new date object
12 var myDate:Date = new Date();
13
14 // create dobMonth arrays
15 // if the month selected is April(4), June(6), September(9), or November(11)
16 var monthArray30:Array = new Array(4,6,9,11);
17 // if the month selected is January(1), March(3), May(5), July(7), August(8), October(10), or December(12)
18 var monthArray31:Array = new Array(1,3,5,7,8,10,12);
19
20 // this is broken... it still won't use 30 or 31
21 // create a listener for dobMonth and dobYear
22 // when these are changed, repopulate dobDate
23 var cbListener:Object = new Object();
24 cbListener.change = function(evt_obj:Object):Void {
25
26 // set monthSelected and yearSelected
27 var monthSelected:Object = dobMonth.selectedItem;
28 var yearSelected:Object = dobYear.selectedItem;
29 trace(monthSelected.data);
30 trace(yearSelected.data);
31
32 // if "monthSelected" is in the array "monthArray30" (4,6,9,11)
33 if(monthArray30.in_array(monthSelected.data)){
34
35 // set popDays to 30
36 var popDays:Number = 30;
37
38 // else, if "monthSelected" is in the array "monthArray31" (1,3,5,7,8,10,12)
39 } else if(monthArray31.in_array(monthSelected.data)){
40
41 // set popDays to 31
42 var popDays:Number = 31;
43
44 // else, if "monthSelected" is 2 (february)
45 } else if(monthSelected.data == "2"){
46
47 // determine if yearSelected is a leap year
48 // if "yearSelected" is divisible by 4, AND NOT 100, or divisible by 400
49 if(((yearSelected.data % 4 == 0) && (yearSelected.data % 100 != 0)) || (yearSelected.data % 400 == 0)){
50
51 // set popDays to 29 (leap year)
52 var popDays:Number = 29;
53
54 // else, if "yearSelected" is NOT a leap year
55 } else {
56
57 // set popDays to 28
58 var popDays:Number = 28;
59
60 } // end if((yearSelected % 4 == 0) && (yearSelected % 100 != 0)) || (yearSelected % 400 == 0)
61
62 } // end if(monthArray30.in_array(monthSelected))
63
64 // populate dobDate with popDays
65 for(var i:Number = 1; i<=popDays; i++){
66
67 dobDate.addItem({data:i, label:i});
68
69 } // end for(var i:Number = 0; i<30; i++)
70
71 };
72
73 // apply listener to dobMonth and Year
74 dobMonth.addEventListener("change", cbListener);
75 dobYear.addEventListener("change", cbListener);
76
77 // create myYears, starting with this year
78 var myYears:Number = myDate.getFullYear();
79
80 // populate dobYear with deincrementing loop,
81 // starting with the current year and going back 80 years
82 for(var i:Number = myYears; i>(myYears-80); i--){
83
84 // populate dobYear data and label with i
85 dobYear.addItem({data:i, label:i});
86
87 } // end for(var i:Number=currentYear; i>(currentYear-80); i--)
What on Earth am I doing wrong? Is addItem an improper method for what I'm doing? If so, what would be better suited for this task?