PDA

View Full Version : 5006: An ActionScript file can not have more...


TheThirdL3g
02-16-2009, 08:15 PM
Ok, i am getting this error when i try to test my movie.
[QUOTE]5006: An ActionScript file can not have more than one externally visible definition: AvoiderGame, moveEnemy[Quote]

My two .as files are:
AvoiderGame.as:
package {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class AvoiderGame extends MovieClip {
public var enemy:Enemy;
public var gameTimer:Timer;


public function AvoiderGame() {
enemy = new Enemy();
addChild( enemy );

gameTimer=new Timer(25);
gameTimer.addEventListener( TimerEvent.TIMER, moveEnemy );
gameTimer.start();
}
}

public function moveEnemy( timerEvent:TimerEvent ):void {
enemy.moveDownABit();
}

}

and

Enemy.as
package {
import flash.display.MovieClip;
public class Enemy extends MovieClip {
public function Enemy() {
x=100;
y=15;
}

public function moveDownABit():void {
y=y+3;
}
}
}

Any help would be appreciated.

wvxvw
02-16-2009, 08:29 PM
What moveEnemy and moveDownABit are meant to be? Seems like you wanted to make them class methods, if so, move them inside the class { -->here<-- } brackets.

TheThirdL3g
02-16-2009, 09:06 PM
Wow thought i had moveEnemy in the class....
thanks =]

-Ev-
02-17-2009, 02:07 AM
What program do you do your AS coding in? Most good programming environments (including the Flash IDE) have code collapsing features that allow you to instantly condense a block of code into a single line. Collapsing your class definition could have told you that moveEnemy was declared outside. This kind of thing is especially useful in classes that reach 1000+ lines of code, even to just close up methods you're not working on at the moment and allow for less scrolling.