Migrate from Flash 6 to 7

  • mofle
  • Born
  • Born
  • mofle
  • Posts: 1

Post 3+ Months Ago

Hi, all you beautiful people.

I'm making a platform game in Flash 6, and I just found out that I need a lot of the features of Flash 7. But when I try to export it to Flash 7 i can't move the player left or right, just jump.

I use Flash 8 Professional.

Can somebody take a look at the code and help me to find the error?

Somebody else told me that the "platform.velocity" is undefined, but I don't know what that means.


Flash 6 swf
Flash 7 swf
Source - Flash 7
Source - Flash 8


This is the code for the player
Code: [ Select ]
vforce = 80;
hforce = 10;
horizontal = 0;
vertical = 5;
friction = .8;
gravity = .5;
accel = 1.7;
rising = false;
falling = true;
lastX = _x;
lastY = _y;
platform = null;
//
function hitPlatforms() {
    var i, y, x;

    for (i=0; i<_root.maxPlatforms; i++) {
        platform = eval("_root.platform"+i);
        y = _y+vertical;
        x = _x+horizontal;
        if (_y<platform._y && y>=platform._y && platform.hitTest(x, platform._y) == true) {
            _y = platform._y;
            falling = false;
            vertical = 0;
            return;
        }
    }
    platform = null;
    return;
}
//
function render() {
    var x, y;
    x = y=0;
    //
    if (Key.isDown(Key.RIGHT) == true) {
        x = hforce;
    }
    if (Key.isDown(Key.LEFT) == true) {
        x = hforce*-1;
    }
    // Horizontal movement
    if (Math.abs(horizontal)<Math.abs(x)) {
        horizontal = x;
    } else {
        horizontal = horizontal*friction;
        if (Math.abs(horizontal)<1) {
            horizontal = 0;
        }
    }
    // Up key (only allowed when not bouncing)
    if (vertical == 0 && Key.isDown(Key.UP) == true) {
        vertical = vforce*-1;
        horizontal = horizontal+platform.velocity;
        platform = null;
        rising = true;
    }
    // ball is travelling upward
    if (rising == true) {
        vertical = vertical*gravity;
        if (Math.abs(vertical)<1) {
            vertical = Math.abs(vertical);
            falling = true;
            rising = false;
        }
    }
    // ball is travelling downward
    if (falling == true) {
        vertical = vertical*accel;
        hitPlatforms();
    }
    //
    lastX = _x;
    lastY = _y;
    //
    _y = _y+vertical;
    _x = _x+horizontal+platform.velocity;
    //
    if (platform != null && platform.hitTest(_x, platform._y, true) == false) {
        vertical = 2;
        falling = true;
    }
}
stop();
  1. vforce = 80;
  2. hforce = 10;
  3. horizontal = 0;
  4. vertical = 5;
  5. friction = .8;
  6. gravity = .5;
  7. accel = 1.7;
  8. rising = false;
  9. falling = true;
  10. lastX = _x;
  11. lastY = _y;
  12. platform = null;
  13. //
  14. function hitPlatforms() {
  15.     var i, y, x;
  16.     for (i=0; i<_root.maxPlatforms; i++) {
  17.         platform = eval("_root.platform"+i);
  18.         y = _y+vertical;
  19.         x = _x+horizontal;
  20.         if (_y<platform._y && y>=platform._y && platform.hitTest(x, platform._y) == true) {
  21.             _y = platform._y;
  22.             falling = false;
  23.             vertical = 0;
  24.             return;
  25.         }
  26.     }
  27.     platform = null;
  28.     return;
  29. }
  30. //
  31. function render() {
  32.     var x, y;
  33.     x = y=0;
  34.     //
  35.     if (Key.isDown(Key.RIGHT) == true) {
  36.         x = hforce;
  37.     }
  38.     if (Key.isDown(Key.LEFT) == true) {
  39.         x = hforce*-1;
  40.     }
  41.     // Horizontal movement
  42.     if (Math.abs(horizontal)<Math.abs(x)) {
  43.         horizontal = x;
  44.     } else {
  45.         horizontal = horizontal*friction;
  46.         if (Math.abs(horizontal)<1) {
  47.             horizontal = 0;
  48.         }
  49.     }
  50.     // Up key (only allowed when not bouncing)
  51.     if (vertical == 0 && Key.isDown(Key.UP) == true) {
  52.         vertical = vforce*-1;
  53.         horizontal = horizontal+platform.velocity;
  54.         platform = null;
  55.         rising = true;
  56.     }
  57.     // ball is travelling upward
  58.     if (rising == true) {
  59.         vertical = vertical*gravity;
  60.         if (Math.abs(vertical)<1) {
  61.             vertical = Math.abs(vertical);
  62.             falling = true;
  63.             rising = false;
  64.         }
  65.     }
  66.     // ball is travelling downward
  67.     if (falling == true) {
  68.         vertical = vertical*accel;
  69.         hitPlatforms();
  70.     }
  71.     //
  72.     lastX = _x;
  73.     lastY = _y;
  74.     //
  75.     _y = _y+vertical;
  76.     _x = _x+horizontal+platform.velocity;
  77.     //
  78.     if (platform != null && platform.hitTest(_x, platform._y, true) == false) {
  79.         vertical = 2;
  80.         falling = true;
  81.     }
  82. }
  83. stop();
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

"somebody else told me that the "platform.velocity" is undefined, but I don't know what that means."
well, he was right. undefined means that it has no value. In previous versions of flash players it works because if that variable was not defined it was assumed as being empty, but that changed since flash player 7.
you have two choices:
1. remove platform.velocity where it appears (it appears in 2 places), so
Code: [ Select ]
horizontal = horizontal+platform.velocity;
becomes
Code: [ Select ]
horizontal = horizontal;
hahaha, for this you can remove the entire line since it's making no differencce ... but make sure the other line where velocity appears, becomes only: _x = _x+horizontal;

2.
Add to your code:
Code: [ Select ]
function render() {
    var x, y;
    var velocity = 0;
    if (platform != null)
        velocity = platform.velocity;
  1. function render() {
  2.     var x, y;
  3.     var velocity = 0;
  4.     if (platform != null)
  5.         velocity = platform.velocity;

then replace platform.velocity with velocity, so
Code: [ Select ]
horizontal = horizontal+platform.velocity;
becomes
Code: [ Select ]
horizontal = horizontal + velocity;


and also give a velocity to each platform ... or just make it 0 when you get the current platform:
Code: [ Select ]
for (i=0; i<_root.maxPlatforms; i++) {
        platform = eval("_root.platform"+i);
        platform.velocity = 0; // my line
  1. for (i=0; i<_root.maxPlatforms; i++) {
  2.         platform = eval("_root.platform"+i);
  3.         platform.velocity = 0; // my line

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 11 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.