Hin C.
Hin C.

Reputation: 15

ActionScript 3 Syntax Errors

I'm new to AS3 and this site. I'm using a tutorial from http://asgamer.com/2009/as3-flash-games-for-beginners-scores-huds-and-user-interface to create my own version of shooting game. The tutorial comes with 1 enemy and 1 game level and I'm trying to add more enemies and levels.

Here's the original Engine.as coding from the tutorial:

package com.asgamer.basics1 
{   import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.Event;

public class Engine extends MovieClip
{

    private var numStars:int = 80;
    public static var enemyList:Array = new Array();
    private var ourShip:Ship;

    private var scoreHUD:ScoreHUD;

    public function Engine() : void
    {
        ourShip = new Ship(stage);
        ourShip.x = stage.stageWidth / 2;
        ourShip.y = stage.stageHeight / 2;
        ourShip.addEventListener("hit", shipHit, false, 0, true);
        stage.addChild(ourShip);


        scoreHUD = new ScoreHUD(stage);
        stage.addChild(scoreHUD);

        for (var i:int = 0; i < numStars; i++)
        {
            stage.addChildAt(new Star(stage), stage.getChildIndex(ourShip));
        }

        addEventListener(Event.ENTER_FRAME, loop, false, 0, true);

    }

    private function loop(e:Event) : void
    {
        if (Math.floor(Math.random() * 90) == 5)
        {
            var enemy:Stinger = new Stinger(stage, ourShip);

            enemy.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
            enemy.addEventListener("killed", enemyKilled, false, 0, true);
            enemyList.push(enemy);
            stage.addChild(enemy);
        }   
    }

    private function enemyKilled(e:Event)
    {
        scoreHUD.updateKills(1);
        scoreHUD.updateScore(e.currentTarget.points);           
    }

    private function removeEnemy(e:Event)
    {
        enemyList.splice(enemyList.indexOf(e.currentTarget), 1);
    }

    private function shipHit(e:Event)
    {
        scoreHUD.updateHits(1);
    }


}
}

For enemies, I've created another enemy named Stinger2 and added it under the first enemy loop as below but I got error 1021 and 5000.

    private function loop(e:Event) : void
    {
        if (Math.floor(Math.random() * 90) == 5)
        {
            var enemy:Stinger = new Stinger(stage, ourShip);

            enemy.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
            enemy.addEventListener("killed", enemyKilled, false, 0, true);
            enemyList.push(enemy);
            stage.addChild(enemy);
        }   
    }

    private function loop(e:Event) : void
    {
        if (Math.floor(Math.random() * 90) == 5)
        {
            var enemy:Stinger2 = new Stinger2(stage, ourShip);

            enemy.addEventListener(Event.REMOVED_FROM_STAGE, removeEnemy, false, 0, true);
            enemy.addEventListener("killed", enemyKilled, false, 0, true);
            enemyList.push(enemy);
            stage.addChild(enemy);
        }   
    }

For levels, I want to create 3 different levels. The first level comes with Stinger only, the second comes with Stinger2 only and the final level comes with both Stinger and Stinger2. There is also a score system from the tutorial, the below coding is from the tutorial, it controls the chance of enemy spawns:

       if (Math.floor(Math.random() * 30) == 5

I tried to change it to:

       if (Math.floor(Math.random() * 30) == 5 && scoreHUD(value:Number) < 10000)

so Stinger only spawns when player's score is below 10000 (level 1) but then I got a error 1084. So how do I add multiple enemies to the array and how to make these enemies spawn between specific scores?

Upvotes: 0

Views: 80

Answers (1)

golyo
golyo

Reputation: 518

Error 1021 means you have two functions with the same name (loop), this is not allowed for obvious reasons.

Error 5000 is sometimes ambiguous, it usually happens when you have other problems in your code.

Error 5000: The class 'myClass' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type

You should take a look at your library in flash to make sure you have the correct base classes declared.

Error 1084 is just a simple syntax error, you are missing a ) in your if statement.

Upvotes: 1

Related Questions