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

  1. function login() {
  2. if (txUser.text.length == 0) {
  3. txError.text = "** Username Required **";
  4. } else if (txPass.text.length == 0) {
  5. txError.text = "** Password required **";
  6. } else {
  7. mcLogin._visible = true;
  8. mcLoader._visible = true;
  9. result_lv = new LoadVars();
  10. log_lv = new LoadVars();
  11. log_lv.user = txUser.text;
  12. log_lv.pass = txPass.text;
  13. log_lv.sendAndLoad(phpPath+"login.php"+secureVar(),result_lv,"POST");
  14. result_lv.onLoad = function(success) {
  15. if (success) {
  16. if (result_lv.retval.length) {
  17. mcLoader.dataLoaded = true;
  18. } else {
  19. trace("error:"+unescape(data_lv));
  20. }
  21. }
  22. };
  23. }
  24. }

Now with AS3 we have

  1. function login() {
  2. if (txUser.text.length==0) {
  3. txError.text = "** Username Required **";
  4. } else if (txPass.text.length==0) {
  5. txError.text = "** Password required **";
  6. } else {
  7. var variables:URLVariables = new URLVariables();
  8. variables.user = txUser.text;
  9. variables.pass = txPass.text;
  10. var request:URLRequest = new URLRequest();
  11. request.url = "login.php";
  12. request.method = URLRequestMethod.POST;
  13. request.data = variables;
  14. var loader:URLLoader = new URLLoader();
  15. loader.dataFormat = URLLoaderDataFormat.VARIABLES;
  16. loader.addEventListener(Event.COMPLETE, completeHandler);
  17. mcLoader.visible=true;
  18. mcDisable.visible=true;
  19. try {
  20. loader.load(request);
  21. } catch (error:Error) {
  22. mcDisable.visible=false;
  23. mcLoader.visible=false;
  24. txError.text="Unable to load URL";
  25. }
  26. function completeHandler(event:Event):void {
  27. restString = "Welcome back <span style="color: #990000;">"+txUser.text+"</span> You were last logged in:<span style="color: #990000;">"+event.target.data.welcomeMessage+"</span>";
  28. //
  29. gotoAndStop(2);
  30. }
  31. }
  32. }

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: , , ,

5 Responses to “First partial look at my converted AS2 to AS3 flash tracking system”

  1. Simple flash AS3 contact form with field validation | Life of a Glasgow Flash Developer Says:

    [...] 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. [...]

  2. Jonatan no te vayas pa lo jondo Says:

    Muy buen tutorial veamos si funciona…

  3. [Paul Ferrie] Says:

    English please

  4. Still At AS2 :( Says:

    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;
    };

  5. [Paul Ferrie] Says:

    Please feel free to email me about any work you need done.

Leave a Reply