在类中使用鼠标单击事件时遇到问题,我是动作脚本的绝对初学者。
我想要的是,如果我单击 btn_MClick 按钮,它应该运行脚本,但是每次单击它时,我都会收到错误消息,表明 btn_MClick 未定义。
btn_MClick 在舞台上,如果 btn_MClick 带有实例名称
public class gunShip1 extends MovieClip
{
var moveCount = 0;
public function gunShip1()
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveGunShip1);
stage.addEventListener(KeyboardEvent.KEY_DOWN, ShootGunShip1)
btn_MClick.addEventListener(MouseEvent.MOUSE_DOWN.KEY_DOWN, ShootGunShip1);;
}
function ShootGunShip1(evt: MouseEvent)
{
var s_Bullet:survBullet = new survBullet();
var stagePos:Point = this.localToGlobal (new Point(this.width / 2-10, this.height));;
s_Bullet.x = stagePos.x;
s_Bullet.y = stagePos.y;
parent.addChild(s_Bullet);
//play sound
var gun_sound:ricochetshot = new ricochetshot();
gun_sound.play();
}
}
拜托,我完全不知道该怎么做,不知何故,感觉整个过程都是错误的。