0
我想做一個簡單的項目,當你點擊一個按鈕一個可拖動的MovieClip被添加到雄鹿,當你點擊它釋放MovieClip到X/Y在您點擊的位置,然後您可以拾取MovieClip並將其拖動到一個可以銷燬自己的bin(MovieClip)中。代碼運行良好我可以使用按鈕製作多個Movieclip,並且當我將它們拖動到bin中時它們全部被銷燬,但是我不喜歡有「錯誤代碼」。AS3的作品,但我得到一個ReferenceError:錯誤#1069屬性startDrag找不到
import flash.events.MouseEvent;
var rubbish:my_mc = new my_mc();
btntest.addEventListener(MouseEvent.CLICK, makeRubbish);
function makeRubbish (event:MouseEvent):void {
addChild(rubbish);
rubbish.x = mouseX - 10;
rubbish.y = mouseY - 10;
rubbish.width = 50;
this.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
rubbish.buttonMode = true;
}
function stopDragging (event:MouseEvent):void {
rubbish.stopDrag()
event.target.addEventListener(MouseEvent.CLICK, startDragging);
rubbish.buttonMode = true;
if (event.target.hitTestObject(bin))
{
trace("hit");
event.target.name = "rubbish";
removeChild(getChildByName("rubbish"));
}
}
function startDragging (event:MouseEvent):void {
event.target.startDrag();
this.addEventListener(MouseEvent.CLICK, stopDragging);
}
嗯,我仍然得到錯誤,但現在全臺移動時,我拖累了,它不喜歡讓垃圾 –
的去再次編輯與完整的代碼。現在就試試。 – shennan
第41行錯誤1118將靜態類型的值強制與可能不相關的類型綁定my_mc –