Hi there, I have a problem with a class, I don’t know how to make it work, mainly because I’m new at using classes.
This is the class sounds.as:
package {
import flash.events.*;
import flash.media.Sound;
import flash.media.SoundChannel;
public class sounds {
public function sounds():void {
addEventListener(KeyboardEvent.KEY_DOWN, keys);
trace("class is working")
}
public function keys(e:KeyboardEvent):void {
if (e.keyCode == 37) {
trace("pressed");
}
}
}
}
I know you may think it has nothing to do with sounds, but I’m just testing it before putting the real code. And the keys functions is because I will need to do something with keys so I’m just testing it.
My problem is:
If I put import sounds; in the main timeline, nothing happens. If I put sounds.sounds() (so the sounds function located inside the sounds class is called) I have a compiler error which says:
1180: Call to a possible undefined method addEventListener
The source is addEventListener(KeyboardEvent.KEY_DOWN, keys);
So basically, what I need is to make the class work. I mean, how to import it and solve that compiler error.
Thanks a lot.