0
votes

I have downloaded this code from the Internet. I need to import the .swf file to Director 8.5, therefore it's required to publish the Flash file using Flash Player 5 with ActionScript 2 support.

The animation runs smoothly while testing it however once I try to publish it in flash player 5 setting it gives some errors which I have not been able to correct after trying for a long time.

The code:

var speed:Number = 0;
var speedMax:Number = 5;
var speedMaxReverse:Number = -2;
var speedAcceleration:Number = .15;
var speedDeceleration:Number = .90;
var groundFriction:Number = .95;

var startingRotation:Number = 180;

var steering:Number = 0;
var steeringMax:Number = 8;
var steeringAcceleration:Number = .10;
var steeringFriction:Number = .98;

var velocityX:Number = 0;
var velocityY:Number = 0;

/**
* Main game loop
*/
function runGame():Void
{
    // UP Arrow or W (accelerate)
    if (Key.isDown(Key.UP) || Key.isDown(87))
    {
        //check if below speedMax
        if (speed < speedMax){
            //speed up
            speed += speedAcceleration;
            //check if above speedMax
            if (speed > speedMax){
                //reset to speedMax
                speed = speedMax;
            }
        }
    }
    // DOWN Arrow or S (reverse) 
    if (Key.isDown(Key.DOWN) || Key.isDown(83))
    {
        //check if below speedMaxReverse
        if (speed > speedMaxReverse){
            //speed up (in reverse)
            speed -= speedAcceleration;
            //check if above speedMaxReverse
            if (speed < speedMaxReverse){
                //reset to speedMaxReverse
                speed = speedMaxReverse;
            }
        }
    }
    // LEFT Arrow or A (turn left)
    if (Key.isDown(Key.LEFT) || Key.isDown(65))
    {
        //turn left
        steering -= steeringAcceleration;
        //check if above steeringMax
        if (steering > steeringMax){
            //reset to steeringMax
            steering = steeringMax;
        }
    }
    // RIGHT Arrow or D (turn right)
    if (Key.isDown(Key.RIGHT) || Key.isDown(68))
    {
        //turn right
        steering += steeringAcceleration;
        //check if above steeringMax
        if (steering < -steeringMax){
            //reset to steeringMax
            steering = -steeringMax;
        }
    }   

    // SPACE (brake)
    if (Key.isDown (Key.SPACE))
    {
        speed = speed * speedDeceleration;
    }

    // friction    
    speed *= groundFriction;

    // prevent drift
    if(speed > 0 && speed < 0.05)
    {
        speed = 0
    }

    // calculate velocity based on speed
    velocityX = Math.sin (player_mc._rotation * Math.PI / 180) * speed;
    velocityY = Math.cos (player_mc._rotation * Math.PI / 180) * -speed;

    // update position  
    player_mc._x += velocityX;
    player_mc._y += velocityY;

    // prevent steering drift (right)
    if(steering > 0)
    {
        // check if steering value is really low, set to 0
        if(steering < 0.05)
        {
            steering = 0;
        }       
    }
    // prevent steering drift (left)
    else if(steering < 0)
    {
        // check if steering value is really low, set to 0
        if(steering > -0.05)
        {
            steering = 0;
        }       
    }

    // apply steering friction
    steering = steering * steeringFriction;

    // make car go straight after driver stops turning
    steering -= (steering * 0.1);

    // rotate
    player_mc._rotation += steering * speed;
}

/**
* onEnterFrame function to repeat runGame() over and over
*/
player_mc.onEnterFrame = function()
{
    runGame()
}

Error

Scene=Scene 1, layer=AS, frame=1:Line 21: '{' expected function runGame():Void

1
I think syntax error, " runGame();"Careen

1 Answers

0
votes

Flash player 5 was Actionscript 1. It doesn't support AS2. That means no data typing. I'm not even sure there were trig functions. It's hard to find a resource on AS1 but I remember using it and using movie clip timeline structures just to implement branching logic. Good luck!