So I followed this tutorial to create an age verification page but I don’t really have the AS knowledge to finish it up.
Problems:
I don’t know how to link the text to the appropriate website when they are verified. EX: “You may enter” linking to the site. “You are not of age” linking to disney.com or something.
Also, when there are no digits entered, it verifies the user of age.
Actionscript below.
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.net.SharedObject;
public class AgeCheck extends MovieClip
{
var hostName:String = "WDAgeChk"
var MINAGE:int = 20;
public function AgeCheck()
{
init();
}
private function init():void
{
// Check SharedLocalData
sharedData();
year_txt.addEventListener(FocusEvent.FOCUS_OUT, onYearOut);
year_txt.addEventListener(FocusEvent.FOCUS_IN, onYearin);
day_txt.addEventListener(FocusEvent.FOCUS_IN, onDayin);
month_txt.addEventListener(FocusEvent.FOCUS_IN, onMonthin);
}
private function onYearOut(evt:FocusEvent):void
{
checkDate();
}
private function onYearin(evt:FocusEvent):void
{
year_txt.text = "";
}
private function onDayin(evt:FocusEvent):void
{
day_txt.text = "";
}
private function onDayOut(evt:FocusEvent):void
{
day_txt.text = "";
}
private function onMonthin(evt:FocusEvent):void
{
month_txt.text = "";
}
private function sharedData():void
{
var mySo:SharedObject = SharedObject.getLocal(hostName);
var myAge:String = mySo.data.age;
if(Number(myAge) < MINAGE){
yourAge_txt.text = "You are not of age.";
// load error page here.
} else {
// enter the web site.
}
}
private function checkDate():void
{
var chk: Date= new Date(year_txt.text, month_txt.text,day_txt.text);
var today: Date = new Date();
var years:Number = today.getFullYear() - chk.getFullYear();
if (years > 20){
yourAge_txt.text = "You may enter.";
//yourAge_txt.addEventListener(MouseEvent.CLICK, onEnter);
} else {
yourAge_txt.text = "You are not of age.";
var mySo:SharedObject = SharedObject.getLocal(hostName);
mySo.data.age = years;
var flushResult:Object = mySo.flush();
}
}
}
}
Thanks, Kaz