Hello everyone, recently I built a site using AS2 as that is what I used when I first learned flash (I have yet to learn AS3).
Most of the site is complete except for one thing. I need to use some sort of Age Verification method to access one section of the site. I would prefer using combo boxes but anything will work fine. I have already searched this site, and while I found a few entries for the same thing none were complete. Finding anything on the net for this in general has been pretty impossible other than for AS3.
If you have any information or tutorials that could help with this it would be greatly appreciated.
Here is what little code I have been able to piece together from other posts:
Action Layer Code:
Code:
stop ();
mon = userMonth.selectedItem;
day = userDay.selectedItem;
year = userYear.selectedItem;
birthDate = new Date(year,mon,day);
todayDate = new Date();
elapsedYears = todayDate.getYear()-birthDate.getYear();
trace("Your birthday is "+userMonth.value+" "+userDay.value+" "+userYear.value);
//Month combobox listener
userMonthListener = new Object();
userMonthListener.change = function(eventObj) {
var eventSource = eventObj.target;
var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.label;
trace("You selected "+theSelectedItemLabel+".");
};
userMonth.addEventListener("change", userMonthListener);
//Month create the items
var item1 = {label:"January", data:01};
var item2 = {label:"February", data:02};
var item3 = {label:"March", data:03};
var item4 = {label:"April", data:04};
var item5 = {label:"May", data:05};
var item6 = {label:"June", data:06};
var item7 = {label:"July", data:07};
var item8 = {label:"August", data:08};
var item9 = {label:"September", data:09};
var item10 = {label:"October", data:10};
var item11 = {label:"November", data:11};
var item12 = {label:"December", data:12};
//Month populate the list box
userMonth.addItem(item1);
userMonth.addItem(item2);
userMonth.addItem(item3);
userMonth.addItem(item4);
userMonth.addItem(item5);
userMonth.addItem(item6);
userMonth.addItem(item7);
userMonth.addItem(item8);
userMonth.addItem(item9);
userMonth.addItem(item10);
userMonth.addItem(item11);
userMonth.addItem(item12);
//Day combobox listener
userDayListener = new Object();
userDayListener.change = function(eventObj) {
var eventSource = eventObj.target;
var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.label;
trace("You selected "+theSelectedItemLabel+".");
};
userDay.addEventListener("change", userDayListener);
//Day populate combobox
for (var day:Number = 0; day<=30; day++) {
userDay.addItem({label: (day+1).toString(), data:day});
}
//Year combobox listener
userYearListener = new Object();
userYearListener.change = function(eventObj) {
var eventSource = eventObj.target;
var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.label;
trace("You selected "+theSelectedItemLabel+".");
};
userYear.addEventListener("change", userYearListener);
//Year populate combobox
for (var year:Number = 1914; year<=1989; year++) {
userYear.addItem({label: (year+1).toString(), data:year});
}
// no delay in comboboxes
var foo = userMonth.dropdown;
var foo = userDay.dropdown;
var foo = userYear.dropdown;
//Set up Button component
checkerListener = new Object();
checkerListener.click = function() {
if ((todayDate.getMonth()<birthDate.getMonth() || (todayDate.getMonth() == birthDate.getMonth() && todayDate.getDate()<birthDate.getDate()))) {
elapsedYears--;
}
trace("Age of user: "+elapsedYears);
if (elapsedYears>=21) {
// pass
gotoAndStop(59);
} else {
// fail
gotoAndStop(49);
}
};
checker.addEventListener("click", checkerListener);
Button Code (Instance name: checker):
Code:
on (release) {
if ((todayDate.getMonth()<birthDate.getMonth() || (todayDate.getMonth() == birthDate.getMonth() && todayDate.getDate()<birthDate.getDate()))) {
elapsedYears--;
}
trace("Age of user: "+elapsedYears);
if (elapsedYears>=21) {
// pass
gotoAndStop(59);
} else {
// fail
gotoAndStop(49);
}
}
All of the combo boxes lables start with the subjec ("Month" for example) then listed entries.
Instance name for combo boxes:
userMonth
userDay
userYear
If you could use any more information please let me know.
Thank you for responding whispers. If I understand you correctly a hard coded date could work if I was able to update the site code myself daily.
As in today if everyone has to be born on/before 07/23/1992 as the hard coded date, but then unless I update the code tomorrow anyone born 07/24/1992 and later wont be able to log on. Therefor I need the code to use the computers clock or something in order to get the correct date for the age.
Unfortunately, my coding knowledge isn't that advanced to get this working and finding the information to do so has been quite difficult. If you have advice or ideas I would appreciate it.
just grab a date.. and use a hardcoded value (18 years) to compare the user age/date against..
example (using combo boxes as input from the user)
Code:
//create a new date instance
var today_date:Date = new Date();
//month array
var monthArray:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
//populate month combobox
for (i = 0; i < 12; i++) {
month_cb.addItem({data:(i), label:monthArray[i]});
}
//populate date combobox
for (i = 0; i < 31; i++) {
day_cb.addItem({data:(i + 1), label:(i + 1)});
}
//populate year combobox
//trace("FULL YEAR: "+today_date.getFullYear());
for (i = (today_date.getFullYear() ); i > (today_date.getFullYear() - 110); i--) {
year_cb.addItem({data:i, label:i});
}
verify_btn.onPress = function(){
//cb entered info
var userMonth = month_cb.selectedItem.data;
var userDate = day_cb.selectedItem.data;
var userYear = year_cb.selectedItem.data;
//user date
var user_date:Date = new Date(userYear, userMonth, userDate);
//increased date:
var olderThan_date:Date = new Date(today_date.getFullYear() - 18, today_date.getMonth(), today_date.getDate());
//compare dates
if(user_date > olderThan_date){
trace("NOT OLD ENOUGH");
//do whatever
}else{
trace("OLD ENOUGH");
//do whatever
}
}