First partial look at my converted AS2 to AS3 flash tracking system
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.
Tags: AS2, AS2-AS3 conversion, AS3, flash statistic's app
April 17th, 2008 at 4:25 pm
[...] This is an example of how AS3 aint all that bad. I simply converted an already existing AS2 contact form to AS3. Looking at the fla you will see that not much has changed. The only major difference is how you setup sending your vars to the php script. An example can be seen here. [...]
May 21st, 2009 at 2:21 pm
Muy buen tutorial veamos si funciona…
May 21st, 2009 at 2:25 pm
English please
May 17th, 2010 at 11:22 am
Could you convert this for me:
this.createEmptyMovieClip(“images”, 100);
this.attachMovie(“mask”, “mask”, 101);
mask._x = images._x =305;
mask._y = target = 96;
images.setMask(mask);
images._y = -1000;
speed = 5;
for (var i = 0; i<8; i++) {
var img = images.attachMovie("image"+i, "image"+i, i);
img._y = img._height*i;
var thumb = this["thumb"+i];
thumb._alpha = 60;
thumb.pos = target+(i*-img._height);
thumb.onPress = function() {
target = this.pos;
};
thumb.onRollOver = function() {
this._alpha = 100;
};
thumb.onRollOut = function() {
this._alpha = 60;
};
}
this.onEnterFrame = function() {
images._y += (target-images._y)/speed;
};
May 17th, 2010 at 11:51 am
Please feel free to email me about any work you need done.