2

我在让这段代码正常工作时遇到了一些问题。我想更改按钮内文本字段上的文本。它有效,但仅适用于 upState。只要我悬停或单击按钮,它就会变回原始名称。有什么办法可以将其定义为 anyState?

var doc:DisplayObjectContainer = m1.upState as DisplayObjectContainer;
var tf:TextField = doc.getChildAt(1) as TextField;

var boldText:TextFormat = new TextFormat();
boldText.bold = true;

tf.text = "Sterno Cleido Mastoid";
tf.setTextFormat(boldText);

示例: http ://www.testdummies.dk/dynamictext.fla

4

2 回答 2

2

Your issue is that your code is only changing the text for the up state of the button. The other states remain unaffected.

You could simply copy and paste your code to do the same change for the over and down states - adding this code after your existing code would do just that:

doc = m1.overState as DisplayObjectContainer;
tf = doc.getChildAt(1) as TextField;
tf.text = "Neck";
tf.setTextFormat(boldText);

doc = m1.downState as DisplayObjectContainer;
tf = doc.getChildAt(1) as TextField;
tf.text = "Neck";
tf.setTextFormat(boldText);

This is an awkward way though to code a simple text change for a button. Creating a custom button class, or even making a movieClip work as a button would be much cleaner. Create a new question if you need help learning either of these things.

于 2012-07-18T23:48:20.990 回答
0

我会将文本字段放在按钮顶部自己的图层上,因此无论按钮状态如何,它始终具有相同的文本。

或者,您可以将该代码复制并粘贴到每个按钮状态中,然后更改代码以反映当前状态。(虽然第一个解决方案更快/更容易)

于 2012-07-18T22:45:13.227 回答