3 Replies Latest reply on Apr 27, 2011 9:20 AM by Ned Murphy

    Convert As2 to As3 - Please Help

    Eppyhexx

      Greetings dear community friends!

       

      I kinda need help with a project for my website, the current code I have is ActionScript 2. And would love to convert it to Actionscirpt, but due to lack of experience I have no idea how to do so.

      So please help me convert this code (as2) to Actionscript 3.

       

      ---------------------------

      Download:  http://www.mediafire.com/?n2yeag9gcfz1b4j

       

       

       

       

      Thanks in advance!


      - Fredde

        • 1. Re: Convert As2 to As3 - Please Help
          Ned Murphy Adobe Community Professional & MVP

          Your chances of getting help will increase if you show your code.  Not everyone is willing/able to chance downloading files.

           

          Also, you double posted this, so before someone gets a chance to response to the other one, it will be nice of you if you delete it.

          • 2. Re: Convert As2 to As3 - Please Help
            Eppyhexx Level 1

            Yepp! My net speed is very low, so it seems I´ve double clicked before letting it load fully.

             

            Code:

             

            Object 1)

             

            stop();
            car1.code = "player";

             

            totalLaps = 10;
            acceleration = 0.4;
            speedDecay = 0.96;
            rotationStep = 10;
            maxSpeed = 10;
            backSpeed = 1;
            currentCheckpoint1 = 1;
            currentLap1 = 0;
            checkpoints = 2;

             

            currentLapTXT = "1/10";

             

            ------------------------------------------------------------------------------

            Object 2)

             

            stop();
            initialTime = getTimer();
            lapTime = initialTime;

             

            -----------------------------------------------------------------------------

            Object 3)

             

            function step(who) {
                //check to see if the car in question is controlled by the player or by the computer
                if (_root["car"+who].code == "player") {
                    //we will constantly decrease speed by multiplying it with a number below 1
                    if (this["speed"+who]>0.3) {
                        this["speed"+who] *= _root.speedDecay;
                    } else {
                        this["speed"+who] = 0;
                    }
                    //the car will react to certain keys
                    //accelerate
                    if (Key.isDown(Key.UP) && this["speed"+who]<_root.maxSpeed) {
                        this["speed"+who] += _root.acceleration;
                    }
                    //brake (reverse)   
                    if (Key.isDown(Key.DOWN)) {
                        this["speed"+who] -= _root.backSpeed;
                    }
                    //steer left   
                    if (Key.isDown(Key.LEFT) && Math.abs(this["speed"+who])>0.3) {
                        _root["car"+who]._rotation -= _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
                    }
                    //steer right   
                    if (Key.isDown(Key.RIGHT) && Math.abs(this["speed"+who])>0.3) {
                        _root["car"+who]._rotation += _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
                    }
                    this["rotation"+who] = _root["car"+who]._rotation;
                    //we calculate the two components of speed (X axis and Y axis)
                    this["speedx"+who] = Math.sin(this["rotation"+who]*(Math.PI/180))*this["speed"+who];
                    this["speedy"+who] = Math.cos(this["rotation"+who]*(Math.PI/180))*this["speed"+who]*-1;
                    //apply the components on the actual position of the car
                    _root["car"+who]._x += this["speedx"+who];
                    _root["car"+who]._y += this["speedy"+who];
                    //the collisions
                    //define the four collision points
                    _root["car"+who].pointLeft = {x:-20, y:0};
                    _root["car"+who].localToGlobal(_root["car"+who].pointLeft);
                    _root["car"+who].pointRight = {x:20, y:0};
                    _root["car"+who].localToGlobal(_root["car"+who].pointRight);
                    _root["car"+who].pointFront = {x:0, y:-25};
                    _root["car"+who].localToGlobal(_root["car"+who].pointFront);
                    _root["car"+who].pointBack = {x:0, y:25};
                    _root["car"+who].localToGlobal(_root["car"+who].pointBack);
                    //let's use some shorter variable names
                    this["lpx"+who] = _root["car"+who].pointLeft.x;
                    this["lpy"+who] = _root["car"+who].pointLeft.y;
                    this["rpx"+who] = _root["car"+who].pointRight.x;
                    this["rpy"+who] = _root["car"+who].pointRight.y;
                    this["fpx"+who] = _root["car"+who].pointFront.x;
                    this["fpy"+who] = _root["car"+who].pointFront.y;
                    this["bpx"+who] = _root["car"+who].pointBack.x;
                    this["bpy"+who] = _root["car"+who].pointBack.y;
                    //check for collisions
                    if (_root.terrain.hitTest(this["lpx"+who], this["lpy"+who], true)) {
                        _root["car"+who]._rotation += 5;
                        this["speed"+who] *= 0.85;
                    }
                    if (_root.terrain.hitTest(this["rpx"+who], this["rpy"+who], true)) {
                        _root["car"+who]._rotation -= 5;
                        this["speed"+who] *= 0.85;
                    }
                    if (_root.terrain.hitTest(this["fpx"+who], this["fpy"+who], true)) {
                        this["speed"+who] = -1;
                    }
                    if (_root.terrain.hitTest(this["bpx"+who], this["bpy"+who], true)) {
                        this["speed"+who] = 1;
                    }
                    //position the shadow of the car   
                    _root["shadow"+who]._x = _root["car"+who]._x-4;
                    _root["shadow"+who]._y = _root["car"+who]._y+2;
                    _root["shadow"+who]._rotation = _root["car"+who]._rotation;
                    //checkpoints
                    if (_root["car"+who].hitTest(_root["checkpoint"+_root["currentCheckpoint"+who]])) {
                        //if the current checkpoint is the start line - increase the lap number
                        if (_root["currentCheckpoint"+who] == 1) {
                            if (_root["currentLap"+who] != 0) {
                                _root.setBestLap();
                            }
                            if (_root["currentLap"+who] == _root.totalLaps){
                                _root.gotoAndStop("finish");
                            }else{
                                _root["currentLap"+who]++;
                            }
                            _root.currentLapTXT = _root["currentLap"+who]+"/10";
                        }
                        _root["currentCheckpoint"+who]++;
                        //if the current checkpoint is the last checkpoint - set the next checkpoint to the start line
                        if (_root["currentCheckpoint"+who]>_root.checkpoints) {
                            _root["currentCheckpoint"+who] = 1;
                        }
                    }
                }
                if (_root["car"+who].code == "computer") {
                }
            }
            function setTimes() {
                timeElapsed = getTimer()-_root.initialTime;
                milliseconds = timeElapsed;
                seconds = Math.floor(milliseconds/1000);
                minutes = Math.floor(seconds/60);
                minutesTXT = minutes;
                secondsTXT = seconds-minutes*60;
                tensTXT = Math.round((milliseconds-seconds*1000)/10);
                if (minutesTXT<10) {
                    minutesTXT = "0"+minutesTXT;
                }
                if (secondsTXT<10) {
                    secondsTXT = "0"+secondsTXT;
                }
                if (tensTXT<10) {
                    tensTXT = "0"+tensTXT;
                }
                _root.totalTimeTXT = minutesTXT+"."+secondsTXT+"."+tensTXT;
            }
            function setBestLap() {
                bestTime = getTimer()-_root.lapTime;
                milliseconds = bestTime;
                if (oldMilliseconds>milliseconds || oldMilliseconds==null) {
                    oldMilliseconds = milliseconds;
                    seconds = Math.floor(milliseconds/1000);
                    minutes = Math.floor(seconds/60);
                    minutesTXT = minutes;
                    secondsTXT = seconds-minutes*60;
                    tensTXT = Math.round((milliseconds-seconds*1000)/10);
                    if (minutesTXT<10) {
                        minutesTXT = "0"+minutesTXT;
                    }
                    if (secondsTXT<10) {
                        secondsTXT = "0"+secondsTXT;
                    }
                    if (tensTXT<10) {
                        tensTXT = "0"+tensTXT;
                    }
                    _root.bestLapTXT = minutesTXT+"."+secondsTXT+"."+tensTXT;
                }
                _root.lapTime = getTimer();
            }

             

             

            ------------------------------------------------------------------------------

            Object 4)

             

            onClipEvent(load){
                speed1 = 0;
            }
            onClipEvent(enterFrame){
                _root.setTimes();
                _root.step(1);
            }

             

            ------------------------------------------------------------------------------

             

             

            I hope someone got the time and nervs converting all this code from as2 to as3, feels like asking a bit much but.. I would really appreciate it!

             

            //

            Eppyhexx

            • 3. Re: Convert As2 to As3 - Please Help
              Ned Murphy Adobe Community Professional & MVP

              Yeah, that's a bit much to expect anyone to convert for you.  You can cross your fingers and hope, but your better bet will be to start learning AS3.  Since you say you'd love to convert it to AS3, and that appears to be the only reason for doing so, then you should love the learning as well.

              1 person found this helpful