A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Migration from AS2 to AS3

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    1

    Migration from AS2 to AS3

    Hello,

    I am new here and thought I might could find some help here. I followed a tutorial to create a small race game, but it is in AS2 and I need to have it in AS3. Is there anybody who could help me? I am not very good in coding and would be happy with any kind of help.
    Thanks in advance

    sechbert





    function step(who) {
    //check if the car is controlled by the computer or by the player (i started like that to leave the possibility to have enemies)

    if (_root["car"+who].code == "player") {
    //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;
    }
    //key controllment

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

    //math.abs means only positive numbers

    //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;
    //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);
    //using 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;
    }


    //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();
    }

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi and welcome,

    just dropping off a HUGE code block and asking for someone to simply convert it to AS3 is a bit of a far fetched request, don't you think, given that it's your first post as well ? We would love to help you, but if you at least TRIED to convert it to AS3 first by yourself, and if you get stuck, then asked for our help, I'm pretty sure a lot more people would be willing to help you If you could at least provide us with an FLA file so that we may check if the game works or not, and then take it step by step from there -- that would be great

    Have a still nice day
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,051
    Quote Originally Posted by Nig 13 View Post
    Hi and welcome,

    just dropping off a HUGE code block and asking for someone to simply convert it to AS3 is a bit of a far fetched request, don't you think, given that it's your first post as well ? We would love to help you, but if you at least TRIED to convert it to AS3 first by yourself, and if you get stuck, then asked for our help, I'm pretty sure a lot more people would be willing to help you If you could at least provide us with an FLA file so that we may check if the game works or not, and then take it step by step from there -- that would be great

    Have a still nice day
    +1^
    who said you cant promote your own brand when your business is earning nothing yet? what is this the luxery times where I hire a promoter. OH YEAH really funny.

  4. #4
    Senior Member
    Join Date
    Aug 2012
    Posts
    124
    how is it suppose help an what is " +1^ " meaning????
    Silly answer

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Quote Originally Posted by Terrencing View Post
    how is it suppose help an what is " +1^ " meaning????
    Silly answer
    It means he agrees with what I said.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  6. #6
    Member
    Join Date
    Sep 2014
    Posts
    77
    Hello All,

    This is another good thread, worth visiting & Testing the codes, I still didn't test them; "Load variables into array" Using three diffrent methods, find it on the following link:

    http://www.bokelberg.de/actionscript/28.html

    Best regards!

    P.S. Sorry this was posted here by mistake.
    Last edited by Dr_flash; 02-09-2015 at 09:05 AM.

  7. #7

  8. #8
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I think we have only few minutes to edit or remove a reply...

    And this is flashkit, not google plus +1 -_-
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  9. #9
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Quote Originally Posted by sechbert View Post
    Hello,

    I am new here and thought I might could find some help here. I followed a tutorial to create a small race game, but it is in AS2 and I need to have it in AS3. Is there anybody who could help me? I am not very good in coding and would be happy with any kind of help.
    Thanks in advance

    sechbert





    function step(who) {
    //check if the car is controlled by the computer or by the player (i started like that to leave the possibility to have enemies)

    if (_root["car"+who].code == "player") {
    //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;
    }
    //key controllment

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

    //math.abs means only positive numbers

    //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;
    //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);
    //using 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;
    }


    //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();
    }

    "I am not very good in coding" Then "get very good in coding". How? Learning Actionscript 3.0, not pretending that someone convert your codes, and copy pasting games from the internet. I don't think you will learn that way. Adobe has many tutorials, and explains the methods, classes, properties, events, etc. A great advice from someone that was a beginner once, and decided start reading and testing A LOT to gain knowledge and experience.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  10. #10
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    921
    Quote Originally Posted by angelhdz View Post
    "I am not very good in coding" Then "get very good in coding".
    You don't really have to do that. Another option would be to hire someone who already is very good. I mean, you don't get to drive when you are not very good at driving, do you. Or you do not cook, when you are not very good at cooking. You call taxi, and you dine at restaurant.
    who is this? a word of friendly advice: FFS stop using AS2

  11. #11
    Senior Member
    Join Date
    Aug 2012
    Posts
    124
    I pay taxi if i afford it, i go restaurant if can pay for it.
    I like drive and good at but have no car.
    I cook well but want eat out sometime.
    I want learn sometime but not have time.

    just a few

    angle help maybe, good coder skill list in sig

  12. #12
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Y'all got good points imo, lol. But from the looks of it, the OP seems to have disappeared without a trace, so converting that to AS3 now would be meaningless... at least I was willing help, but OP was asking for too much.

    To add to you guys' "chain" of advice -- sometimes you just ain't got what it takes to learn how to drive or how to cook no matter how many times you try. That's when you resort to help from others, most likely close friends, 'cause I'm sure no stranger would drive to x destination or cook a meal y for you, unless that person's heart is of gold. Just my 2 cents, lolz
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  13. #13
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    921
    but there must be something you're good at, no? and by doing that you're supposed to earn moneys to afford taxi rides and fine dinners. or else, your life is going to be very sad
    who is this? a word of friendly advice: FFS stop using AS2

  14. #14
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    true, but not every talent is of "value" in today's world. No matter how amazing you're at one specific thing, if it doesn't sell, your life is unfortunately going to be sad. But then again:

    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  15. #15
    Member
    Join Date
    Sep 2014
    Posts
    77
    Quote Originally Posted by whispers View Post
    If it was posted in error.. then you should have removed it.
    //_root.onEnterFrame=function(){
    //
    //trace("NO COMMENT!");
    //
    //}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center