PDA

View Full Version : [AS3] Error 1078: Label must be a simple identifer


Rtaos
06-14-2011, 08:02 AM
I am making a Flash game where you move a gun left to right across the screen to shoot at targets above. It has four external actionscripts: the game code itself, the gun object, the target object and the bullet objects.

The problem is with the gun object actionscript named: lGun. The game will not play and comes up with error 1078: label must be a simple identifer. The offending code is marked with a smilie.

lGun external actionscript file:
<as>
package {
import flash.display.*;
import flash.events.*;
import flash.utils.getTimer;

public class lGun extends MovieClip {
static const speed:Number = 150.0;
private var lastTime:int; // animation time

public function lGun() {
//intial location of gun
this.x = 275;
this.y = 340;

//movement
:(addEventListener(Event.ENTER_FRAME,movelGun): //this code has error 1078.
}
}

public function movelGun(event:Event) {
//get time difference
var timePassed:int = getTimer()-lastTime;
lastTime += timePassed;

// current position
var newx = this.x;

//move to the left
if (MovieClip(parent).leftArrow) {
newx -= speed*timePassed/1000;

}

//move to the right
if (MovieClip(parent).rightArrow) {
newx += speed*timePassed/1000;
}

//check boundaries
if (newx < 10) newx = 10;
if (newx > 540) newx = 540;

//reposition
this.x = newx;
}

// remove from screen and remove events
public function deletelGun() {
parent.removeChild(this);
removeEventListener(Event.ENTER_FRAME,movelGun);
}
}
}
</as>

This is a really odd error and I doubt there's a problem with the actionscript but somewhere else in the program. This is a tough one but any assistance people can provide will be much appreciated.

PS: Tried to use the as tags, didn't work sorry. I'm in a bit of a rush.

henke37
06-14-2011, 08:20 AM
Colon instead of semicolon at the end of the line.

Rtaos
06-14-2011, 09:13 AM
Ahh, thanks very much.

But now I've got another problem. Error 5006: An actionscript can not have more than one externally visible defintion: lGun, movelGun.

It thinks the movelGun is a second class but it isn't as it's inside the public class.

package {
import flash.display.*;
import flash.events.*;
import flash.utils.getTimer;

public class lGun extends MovieClip {
static const speed:Number = 150.0;
private var lastTime:int; // animation time

public function lGun() {
//intial location of gun
this.x = 275;
this.y = 340;

//movement
addEventListener(Event.ENTER_FRAME,movelGun);
}
}

:confused:public function movelGun(event:Event) { //It's inside the public class...
//get time difference
var timePassed:int = getTimer()-lastTime;
lastTime += timePassed;

This one is even more confusing than the last. Any help please?