我想刪除我在屏幕上創建的框。我有一個框導出爲 框和導出爲播放器的船,它們都是影片剪輯。這是代碼:刪除鼠標單擊as3上的框
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Main extends MovieClip {
//playermovevar
private var _player:MovieClip;
private var _playerSpeed:Number=5;
private var _destinationX:int;
private var _destinationY:int;
//boxaddvar
private var boxAmount:Number=0;
private var boxLimit:Number=20;
private var _root:Object;
public function Main() {
createPlayer();
//playermovlisten
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseHandlerdown);
//boxaddlisten
addEventListener(Event.ENTER_FRAME, eFrame);
_box.addEventListener(MouseEvent.CLICK, boxclick);
}
//playermoving
private function createPlayer():void {
_destinationX=stage.stageWidth/2;
_destinationY=stage.stageHeight/2;
_player = new Player();
_player.x=stage.stageWidth/2;
_player.y=stage.stageHeight/2;
stage.addChild(_player);
}
private function enterFrameHandler(event:Event):void {
_player.x += (_destinationX - _player.x)/_playerSpeed;
_player.y += (_destinationY - _player.y)/_playerSpeed;
}
private function mouseHandlerdown(event:MouseEvent):void {
_destinationX=event.stageX;
_destinationY=event.stageY;
addEventListener(MouseEvent.MOUSE_UP, mouseHandlerup);
rotatePlayer();
}
private function mouseHandlerup(event:MouseEvent):void {
}
private function rotatePlayer():void {
var radians:Number=Math.atan2(_destinationY-_player.y,_destinationX-_player.x);
var degrees:Number = radians/(Math.PI/180) + 90;
_player.rotation=degrees;
}
//boxadding
private function eFrame(event:Event):void {
if (boxAmount<=boxLimit) {
boxAmount++;
var _box:Box=new Box ;
_box.y=Math.random()*stage.stageHeight;
_box.x=Math.random()*stage.stageWidth;
addChild(_box);
} else if (boxAmount >= boxLimit) {
removeEventListener(Event.ENTER_FRAME, eFrame);
} else {
addEventListener(Event.ENTER_FRAME, eFrame);
}
}
function boxclick(event:MouseEvent):void {
removeChild(_box);
}
}
它給我這個錯誤:
1120:未定義的屬性_box的訪問。 _box.addEventListener(MouseEvent.CLICK,boxclick);
1120:訪問未定義的屬性_box。 removeChild之(_box);
有人知道最新錯了嗎?
感謝
運作良好,但只有2件事(1)我必須點擊其他地方之前,我點擊另一個盒子。 (2)(我想我忘了說這個)當我點擊它需要重新出現在舞臺上的其他地方的盒子。感謝雖然它幫助很大 – thor625 2012-01-05 19:43:04
在這種情況下,不要刪除框,只要移動它。函數boxclick(evt:MouseEvent):void { \t \t \t //removeChild (evt.currentTarget as Box); \t \t \t \t \t \t _box = evt.currentTarget如框; \t \t \t \t \t \t _box.y =的Math.random()* stage.stageHeight; _box.x = Math.random()* stage.stageWidth; } – crooksy88 2012-01-05 20:13:46
我認爲這是有效的,但我寧願它刪除並重新添加到其他地方而不是移動它 – thor625 2012-01-05 20:34:38