简体   繁体   English

Flash AS3如何更改按钮内文本框的值?

[英]Flash AS3 How to i change a value of a textbox inside a button?

Hello and thanks for taking time helping me :) 您好,感谢您抽出宝贵时间帮助我:)

I have a button named "bt_buy_1" and inside it i have a textfield named "price_1" and i want to change the value of the textfield "price_1" so it raise by 50 each time u click it but not that my real problem... my real problem is that i dont know how to change a textbox when its inside a button... i can do it with a symbol (MovieClip) but with a button i cant... :( 我有一个名为“ bt_buy_1”的按钮,并且在其中有一个名为“ price_1”的文本字段,我想更改文本字段“ price_1”的值,因此每次您单击它都会增加50,但这并不是我的真正问题。我真正的问题是我不知道如何在按钮内更改文本框...我可以用符号(MovieClip)来做,但是我不能用按钮... :(

so do any one know how to change the textfiled inside a button? 那么有人知道如何更改按钮内的文本文件吗?

Thanks in advance :) 提前致谢 :)

Quote: 引用:

i can do it with a symbol (MovieClip) but with a button i cant... 我可以用一个符号(MovieClip)来做,但是我不能用一个按钮...

Since you know how to change text inside an MC why not do it that way? 既然您知道如何在MC中更改文本,为什么不这样做呢? If the problem is having something "clickable" then you must know that actually MCs can be clickable too just like buttons (also can listen out for pointer rollovers, button press/release etc etc) 如果问题出在某些“可点击的”问题上,那么您必须知道实际上MC也可以像按钮一样被点击(也可以侦听指针翻转,按钮的按下/释放等)。

Anyways to make your MC behave like a button here is some quick example code to test. 无论如何,要使您的MC像按钮一样工作,这里有一些要测试的快速示例代码。

var cashCount:Number = 0; 

button_MC.buttonMode = true;
button_MC.addEventListener(MouseEvent.CLICK, increaseCash);

function increaseCash (e:MouseEvent):void
{
 cashCount += 50; //increments up by 50 when MC is clicked
 button_MC.cashAmount.text = String(cashCount);
 trace("Clicked for Cash.. amount is now: " + cashCount);
}

Note: cashAmount is the textbox instance name, button_MC is the instance name of the MovieClip you want clickable. 注意: cashAmount是文本框实例名称, button_MC是您希望单击的MovieClip的实例名称。 Also "embed font" on your text if there's a problem displaying the numbers adding up (it happens sometimes, y'know). 如果显示的数字相加时出现问题,也可以在文本上“嵌入字体”(有时会发生,您知道)。 Peace out. 和平了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM