我试图通过使用键盘上的“A”键单击按钮来做到这一点。我为这个按钮创建了两个框架,但代码不起作用,尽管没有错误。
我需要在主课上放什么吗?任何人都可以帮助解决这个问题吗?
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
public class controlButton extends MovieClip {
public function controlButton() {
// constructor code
this.addEventListener(KeyboardEvent.KEY_DOWN,clickDown);
this.addEventListener(KeyboardEvent.KEY_UP,clickUp);
}
public function clickDown(event:KeyboardEvent):void{
// if the key is A
if(event.charCode == 65){
this.gotoAndStop(2);
}
}
public function clickUp(event:KeyboardEvent):void{
// if the key is A
if(event.charCode == 65){
this.gotoAndStop(1);
}
}
public function changelabel(newLabel:String):void{
this.label.text = newLabel;
}
}
}