0
내가 얻으려고하는 것은 카우보이가 클릭되었을 때 사라지는 것입니다. 카우보이가 클릭되었을 때 아무런 흔적도 남기지 않았다.ActionScript3 MouseEvent.CLICK이 오류없이 작동하지 않습니다.
프로그램을 실행할 때 오류가 발생하지 않습니다. 나는 이유를 알 수 없다. 다음은 내 코드입니다
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Bitmap;
import flash.ui.Mouse;
import flash.events.MouseEvent;
/**
* ...
* @author Callum Singh
*/
public class Main extends Sprite
{
public var gun:crosshair;
public var cowboy:enemy;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
gun = new crosshair();
stage.addChild (gun);
addEventListener(Event.ENTER_FRAME, moveCrosshair);
cowboy = new enemy();
cowboy.x = Math.random() * 600;
cowboy.y = Math.random() * 400;
stage.addChild (cowboy);
addEventListener(MouseEvent.CLICK, handleShoot);
}
private function moveCrosshair(e:Event):void
{
gun.x = mouseX -120;
gun.y = mouseY -115;
}
private function handleShoot(e:MouseEvent):void
{
if (e.target == cowboy)
{
cowboy.visible = false;
}
}
}
}
치료를 받았다. 감사. –