2010-11-12 106 views
0

當我試圖在舞臺上創建一個按鈕時,我將這四個錯誤刪除了我在輸入文本中輸入的文本(ti)。根據我有的腳本和錯誤,我應該寫些什麼來創建刪除按鈕?製作刪除按鈕以刪除輸入文本字段中的文本

Attempt to delete the fixed property text. Only dynamically defined properties can be deleted. Access of undefined property delete_btn. Access of possibly undefined property buttonDown through a reference with static type Class. Warning: 3600: Thdeclared property text cannot be deleted. To free associated memory, set its value to null.

delete_btn.addEventListener(MouseEvent.buttonDown, deletetxt); 
function deletetxt(event:TextEvent):void { 
delete ti.text 
} 
ti.border = true 
ti.addEventListener(TextEvent.TEXT_INPUT, onInput); 
function onInput(event:TextEvent):void { 
if(ti.text.search('a')!=-1) load_image("http://i54.tinypic.com/anom5d.png", "ottefct"); 
else if(ti.text.search('b')!=-1) load_image("http://i53.tinypic.com/2dv7dao.png", "rnd"); 
else if(ti.text.search('c')!=-1) load_image("http://i51.tinypic.com/m8jp7m.png", "ssd"); 
} 

var loaded_images:Dictionary = new Dictionary(); 

function load_image(url:String, id_name:String) 
{ 
    var loader:Loader = new Loader(); 
    loader.name = id_name; 
    var url_req:URLRequest = new URLRequest(url); 
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadingComplete); 
    loader.load(url_req); 
} 

function onLoadingComplete(evt:Event):void 
{ 
    var img_name:String = evt.currentTarget.loader.name 
    var spr_box:Sprite = new Sprite(); 
    spr_box.addChild(evt.currentTarget.loader); 

    spr_box.mouseChildren = false; 
    spr_box.doubleClickEnabled = true; 

    spr_box.addEventListener(MouseEvent.MOUSE_DOWN, drag); 
    spr_box.addEventListener(MouseEvent.MOUSE_UP, drop); 
    spr_box.addEventListener(MouseEvent.MOUSE_WHEEL, rotate); 
    spr_box.addEventListener(MouseEvent.DOUBLE_CLICK , unrotate); 


    spr_box.width = 124; 
    spr_box.height = 180; 


    this.addChild(spr_box); 
    loaded_images[img_name] = spr_box; 
} 


function drag(evt:MouseEvent):void 
{ 
    evt.currentTarget.startDrag() 
} 

function drop(evt:MouseEvent):void 
{ 
    evt.currentTarget.stopDrag() 
} 

function rotate(evt:MouseEvent):void 
{ 
    evt.currentTarget.rotation = 90 
} 

function unrotate(evt:MouseEvent):void 
{ 
    evt.currentTarget.rotation = 0 
} 

回答

3

你有幾個錯誤!

嘗試刪除固定屬性文本。只有動態定義的屬性才能被刪除。警告:3600:聲明的屬性文本不能被刪除。要釋放關聯的內存,請將其值設置爲null。

有一個錯誤,當您要刪除的文字:

function deletetxt(event:TextEvent):void { 
    delete ti.text; // <-- Error HERE! 
} 

你應該這樣做,而不是:

function deletetxt(event:MouseEvent):void { // <-- Sorry, didn't see the "TextEvent" 
    ti.text = ""; 
} 

delete關鍵字用於其他事情(如刪除字典條目)

訪問未定義的屬性delete_btn

  • 在這裏,你不已經創建了「delete_btn」按鈕(或它還有另一個實例名稱)通過靜態類型類的引用可能未定義的屬性的buttonDown的

訪問

  • MouseEvent.buttonDown不存在,也許你想使用MouseEvent.CLICKMouseEvent.MOUSE_DOWN代替
+0

我得到這個錯誤now.TypeError:錯誤#1034:類型強制失敗:無法將flash.events::[email protected]轉換爲flash.events.TextEvent。 – starfox55 2010-11-12 04:02:05

+0

是的,對不起,我沒有看到TextEvent,它應該是MouseEvent(或者只是Event) – 2010-11-12 11:42:53

0
delete_btn.addEventListener(MouseEvent.CLICK, deletetxt); 
function deletetxt(event:Event):void { 
ti.text = ""; 
} 

Unkiwii是對的ti.text =「」,但脅迫無法轉換活動,所以我只是做它的事件:

+2

你應該改變事件:Event to event:MouseEvent – Allan 2010-11-12 05:09:46