So, I'm having this error with AS3. I have an object(movie clip) called Inimigo2_Caique2, and his is called Inimigo2_Caique2, too. (I don't know why, but the icon of the object in the library is green instead of blue).
When I try to run the file, I get this error message:
5006: An ActionScript file can not have more than one externally visible definition: Inimigo2_Caique2, removeListeners
I have other object called Inimigo_Caique2, and another class called Inimigo_Caique2. (The icon is green too.)
Here is the code of my Inimigo2_Caique2 class:
package{
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Sprite;
public class Inimigo2_Caique2 extends Sprite{
private var palco:Object;
private var yd:Number;
private var xd:Number;
public function Inimigo2_Caique2(){
addEventListener(Event.ADDED_TO_STAGE,inicia2);
}
private function inicia2(e:Event){
palco=MovieClip(root);
yd=palco.aviao.y-y;
xd=palco.aviao.x-x;
addEventListener(Event.ENTER_FRAME,loop1);
}
private function loop1(e:Event){
var angulo:Number=Math.atan2(yd,xd);
x+=Math.cos(angulo)*10;
y+=Math.sin(angulo)*10;
for(var i:int = 0; i<palco.recipiente.numChildren;i++){
var alvoBala2:Sprite = palco.recipiente.getChildAt(i);
var ris:Number=alvoBala2.y-y;
var run:Number=alvoBala2.x-x;
var dis:Number=Math.sqrt(Math.pow(ris,2)+Math.pow(run,2));
if(dis<100){
if(run<0){
x+=20;
}else{
x-=20;
}
}
}
if(hitTestObject(alvoBala2)){
palco.recipiente.getChildAt(i).removeListeners();
palco.recipiente.removeChild(alvoBala2);
palco.Som2.play();
var boom3:MovieClip = new explosao();
boom3.x=x;
boom3.y=y;
stage.addChild(boom3);
palco.pontos+=300;
var textopontos=String(palco.pontos);
palco.txt_pontos.text=textopontos;
removeEventListener(Event.ENTER_FRAME,loop1);
palco.removeChild(this);
}
}
if(hitTestObject(palco.aviao)){
palco.Som2.play();
var aviaoboom:MovieClip = new explosao();
aviaoboom.x=palco.aviao.x;
aviaoboom.y=palco.aviao.y;
stage.addChild(aviaoboom);
palco.gotoAndStop(2);
}
}
public function removeListeners():void{
removeEventListener(Event.ENTER_FRAME,loop1);
}
}
I don't know why this is happening. I've already checked the brackets and everything, but nothing works.
Thanks in advance. This error is driving me mad.
In the following case, the function myFunction
is outside of the public class Main
and interpreted as another class by the compiler:
My class
package
{
import flash.display.MovieClip;
public class Main extends MovieClip
{
}
//
public function myFunction()
{
}
//
}
My Fla
myFunction(); // function invoked
This error message occurs: 5006: An ActionScript file can not have more than one externally visible definition: Main, myFunction, because the correct code is:
My class
package
{
import flash.display.MovieClip;
public class Main extends MovieClip
{
public function myFunction()
{
trace('myFunction should be here');
}
}
}
So your error message indicates that your function removeListeners
is outside of your class Inimigo2_Caique2
Remark
As MasterRoro says, this block seems to be outside your loop1 function:
if (hitTestObject(palco.aviao)) {
palco.Som2.play();
var aviaoboom:MovieClip = new explosao();
aviaoboom.x=palco.aviao.x;
aviaoboom.y=palco.aviao.y;
stage.addChild(aviaoboom);
palco.gotoAndStop(2);
}