As mentioned in my first entry I have started to mess around with AS3.
I have to say that the first couple of days i would have expected to be the hardest but not atol. As soon as i saw the new way i would normally do ‘x’ it was easy.
An example of how i would load data into flash AS2 from a php script
-
function login() {
-
if (txUser.text.length == 0) {
-
txError.text = "** Username Required **";
-
} else if (txPass.text.length == 0) {
-
txError.text = "** Password required **";
-
} else {
-
mcLogin._visible = true;
-
mcLoader._visible = true;
-
result_lv = new LoadVars();
-
log_lv = new LoadVars();
-
log_lv.user = txUser.text;
-
log_lv.pass = txPass.text;
-
log_lv.sendAndLoad(phpPath+"login.php"+secureVar(),result_lv,"POST");
-
result_lv.onLoad = function(success) {
-
if (success) {
-
if (result_lv.retval.length) {
-
mcLoader.dataLoaded = true;
-
} else {
-
trace("error:"+unescape(data_lv));
-
}
-
}
-
};
-
}
-
}
Now with AS3 we have
-
function login() {
-
if (txUser.text.length==0) {
-
txError.text = "** Username Required **";
-
} else if (txPass.text.length==0) {
-
txError.text = "** Password required **";
-
} else {
-
var variables:URLVariables = new URLVariables();
-
variables.user = txUser.text;
-
variables.pass = txPass.text;
-
var request:URLRequest = new URLRequest();
-
request.url = "login.php";
-
request.method = URLRequestMethod.POST;
-
request.data = variables;
-
var loader:URLLoader = new URLLoader();
-
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
-
loader.addEventListener(Event.COMPLETE, completeHandler);
-
mcLoader.visible=true;
-
mcDisable.visible=true;
-
try {
-
loader.load(request);
-
} catch (error:Error) {
-
mcDisable.visible=false;
-
mcLoader.visible=false;
-
txError.text="Unable to load URL";
-
}
-
function completeHandler(event:Event):void {
-
restString = "Welcome back <span style="color: #990000;">"+txUser.text+"</span> You were last logged in:<span style="color: #990000;">"+event.target.data.welcomeMessage+"</span>";
-
//
-
gotoAndStop(2);
-
}
-
}
-
}
In order to see the flash stats app working you need to first login with usename: client passowrd:client
This application is still work in progress and i am only tracking entry clicks at this point. Though work has started on registering clicks within flash. I should give a thanks to Jason at moogleMedia.com for helping me get a head start on this.