Hi, I’m new around here. I am doing my final year project with Flash CS5. I 'm trying to do that pressing two keys the program go to the next frame , for this I have been guided tutorial “multiple key detection” , but to run the program I get the following error: 5007 an ActionScript file must have at least one definition externally visible . I do not know what to do, could you help me? I’m not very expert in Flash yet. Excuse my English . Thank you.
Hey Xooo, it’s hard to identify what the problem is exactly. Perhaps you could post your code here?
Hi I am using the tutorial found on this site about " Multiple Key detection" that provided a archivo.as :
/* Created to allow us to listen for key combinations.
*
- author Michael Avila
- version 1.0
*/
class KeyDetection {
// a list of all the key codes that have been pressed
private var keys_pressed:Array;
// a multi-dimensional list of all of our key combinations
private var key_combinations:Array;
// objects listening to this detection
private var listeners:Array;
/* Constructor /
public function KeyDetection() {
keys_pressed = new Array();
key_combinations = new Array();
listeners = new Array();
// allow this object to listen for events from the key object
Key.addListener(this);
}
/ Registers an object to listen for events from the KeyDetection class
*
* param The object that will listen for the events
/
public function addListener(listener:Object):Void {
for (var i:Number = 0; i<listeners.length; i++) {
if (listeners[i] == listener) {
return;
}
}
listeners.push(listener);
}
/ Unregisters an object that is listening for events from the KeyDetection class
*
* param The object you wish to remove from the listeners list
/
public function removeListener(listener:Object):Void {
for (var i:Number = 0; i<listeners.length; i++) {
if (listeners[i] == listener) {
listeners.splice(i, 1);
}
}
}
/ Adds a key combination to listen for
*
* param The name you are giving this combination. Note that this is how you will identify which combination
* has been pressed.
* …
* param The key codes that you are part of this combination. Note that they will need to be pressed in the order
* that you list them in order for the combination to be fire successfully.
*
* usage
var key_detector = new KeyDetection();
* key_detector.addCombination(“undo”, Key.CONTROL, 90);
*
*
*/
public function addCombination(name:String, keyCode1:Number, keyCode2:Number):Void {
key_combinations.push(arguments);
}
// invokes the onKeyCombination event on all listeners
private function invokeOnKeyCombination(combo_name:String):Void {
for (var i:Number = 0; i<listeners.length; i++) {
listeners[i].onKeyCombination(combo_name);
}
}
private function onKeyDown() {
var key:Number = Key.getCode();
cleanKeysPressed();
if (key != keys_pressed[keys_pressed.length-1]) {
keys_pressed.push(key);
}
checkCombinations();
}
private function checkCombinations() {
for (var j:Number = 0; j<key_combinations.length; j++) {
for (var i:Number = 0; i<keys_pressed.length; i++) {
if (keys_pressed[i] == key_combinations[j][i+1]) {
if (i == key_combinations[j].length-2) {
invokeOnKeyCombination(key_combinations[j][0]);
return;
}
} else {
break;
}
}
}
}
private function cleanKeysPressed() {
for (var i:Number = 0; i<keys_pressed.length; i++) {
if (!Key.isDown(keys_pressed[i])) {
keys_pressed.splice(i, (keys_pressed.length-i));
}
}
}
}
Now in my program I have used this code:
var keyDet = new KeyDetection();
keyDet.addCombination(“teclaQ+Derecha”, 39, 81);
myObj = new Object();
myObj.onKeyCombination = function(name:String) {
switch (name) {
case “teclaQ+Derecha” :
gotoAndPlay (6);
break;
}
};
keyDet.addListener(myObj);
What I want you to do is to simultaneously press the Q key and the arrow to the right, the program jumps to Frame 6. But when compiling the program gives me the problem 5007 : AstionScript file must have at least one externally visible definition , the error tells me he is on Frame 1 of KeyDetection.as file.And from here I do not know how to fix the error. I use Flash CS6 , but my file is saved as CS5.
Looking at your code, I’m guessing the problem lies in the KeyDetection.as class file.
In the first line:
class KeyDetection {
There should be a public keyword before the class keyword like so:
public class KeyDetection {
The default attribute for a class is set to internal… which only allows access to other class files and code within the same directory or folder… this includes sub-folders.
So to allow access of a class file from anywhere within your project, you have to add the public keyword before the class declaration.
If that doesn’t help, feel free to zip up your files and send me a private message with your file attached
Hello again. Call me clumsy , but I’m new at this. I’m trying to send a private message with my code, but do not know how to do it …
Not a problem =) I’ve sent you a PM with my email address so you could send it there.
Hey Xooo, are you still having trouble with your code? Let me know if I can be of help =)
Hello, thank you very much for your help. As there was a way to do decided to give me a different animation program, as urged me . Thank you for your help .
Alright =) All the best to you