2010-11-12 111 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