Can't click on a class in flash, can't add click EventListener in class .as file :C

74 Views Asked by At

Alright so I have laboured all day to make an Enemy appear in my flash game, one that will go away after a certain number of clicks, however I learned that I can't click on EnemyShip in the main file, so I have to add the click listener into the .as package file. When I attempt to do this, I get the error 5006: An Actionscript file cannot have more than one externally visible definition: clickCount, EnemyShip.

Research suggests this is some sort of curly brace formatting error but I honestly have no clue what to do. :c Please help! And please use simple words, I am a noob with Actionscript 3 ;0;

package{

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent
var clickCount:int = 0;
public class EnemyShip extends MovieClip{


    public function EnemyShip(){

        this.x = 900;
        this.y = 214;

        addEventListener("enterFrame", enterFrame);
        addEventListener(MouseEvent.CLICK, addClick);

    }

function addClick(event:MouseEvent):void {
  clickCount++;
  trace ("clickage");
}
    function enterFrame(e:Event):void{


        if(this.x < -100){
            removeEventListener("enterFrame", enterFrame);
            stage.removeChild(this);
        }

    }

}

}
2

There are 2 best solutions below

0
On BEST ANSWER

Your issue is likely this line:

var clickCount:int = 0;

It is not contained within your class and is with the imports. All code needs to be wrapped in the class declaration.

If you move that line so it's within your class, the error should go away.

package{

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent

public class EnemyShip extends MovieClip {
    private var clickCount:int = 0;

....rest of code
0
On

nevermind, i figured out what happened. the hit clip was not on the main stage, it was contained in a movie clip. i moved the actionscript and the hit clip onto the main stage and received a trace.