HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Frogger game in Actionscript 3

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
actionscriptgamefrogger

Problem

I am creating a Frogger game in Flash AS3 and just wanted to see if anyone can help me improve it without breaking the game.

The reason I ask for it because I don't have any errors, but I do get over 50 of these:


Warning: 3596: Duplicate variable definition.

```
package {

import flash.display.*;
import flash.events.*;
import flash.ui.*;

public class Frogger extends MovieClip
{
private var life, timeElapsed, totalTimer:Number;
private var p1speedX, p1speedY:Number;
private var gotoWin, gotoLose, standingOnLog:Boolean;
private var logs, Trucks, homes, logsYPos, TrucksYPos:Array;

public function startMenu()
{
btnStartGame.addEventListener(MouseEvent.CLICK, gotoStartGame);
stop();
}

public function startWin()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}

public function startLose()
{
btnBack.addEventListener(MouseEvent.CLICK, gotoMenu);
}

public function startGame()
{
timeElapsed = 0;
totalTimer = 60;
life = 3;
p1speedX = 0;
p1speedY = 0;
gotoWin = false;
gotoLose = false;
standingOnLog = false;
Trucks = new Array();
logs = new Array();
homes = new Array();
logsYPos = new Array(115,165,215,265);
TrucksYPos = new Array(365,415,465,515);

setupGame();

addEventListener(Event.ENTER_FRAME,update);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);
stage.focus = this;

for (var i=1; i 0)
{
if (mcP1.x + 50 0)
mcP1.x -= 50;
p1speedX = 0;
mcP1.rotation = -90;
mc

Solution

It is just a warning. The source of the warnings is that you redeclare the same variable newTruck:Truck numerous times in your startGame function as well as newLog:LogWood.

It's just a warning, because it is ok to do so. The reason it warns you is that it might not be your intention to do so, therefore helping you out.

If you want to get rid of those, you can declare the variables once in startGame before the loops like this:

var newTruck:Truck;


and then just reuse them in your loops, for example:

newTruck = new Truck();

Code Snippets

var newTruck:Truck;
newTruck = new Truck();

Context

StackExchange Code Review Q#35622, answer score: 4

Revisions (0)

No revisions yet.