如何在Flash中使用AS3动态更改按钮标签?
我可以运行下面的代码,其中答案是悬停在按钮上的动态文本框。但是,用户无法单击文本框与其重叠的按钮。我需要一种方法来分配按钮标签(如下面的 4 个文本框),或者使其文本框不会干扰单击按钮?任何建议将不胜感激,谢谢!
var myXML:XML = new XML();
var XML_URL:String = "http://localhost/connect.php";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
var finalXML:XML = XML(myLoader.data);
trace(finalXML);
trace("Data loaded.");
trace(finalXML.triviaQuestion[0].answer1[0]);
questionBox.text = finalXML.triviaQuestion[0].question[0];
answerText1.text = finalXML.triviaQuestion[0].answer1[0];
answerText2.text = finalXML.triviaQuestion[0].answer2[0];
answerText3.text = finalXML.triviaQuestion[0].answer3[0];
answerText4.text = finalXML.triviaQuestion[0].answer4[0];
}
更新:我发现以下内容可以更改标签,但是我很困惑如何对已经创建的按钮执行此操作,也许使用实例名称?
var myButton:Button = new Button();
myButton.label = "Click me";
I can run the code below, where the answers are dynamic text boxes hovering over the buttons. However, the user can't click the button where the textbox overlaps it. I need a way to either assign button labels like the 4 text boxes below or make it so the textboxes do not interfere with clicking the button? Any suggestions would be appreciated, thanks!
var myXML:XML = new XML();
var XML_URL:String = "http://localhost/connect.php";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
var finalXML:XML = XML(myLoader.data);
trace(finalXML);
trace("Data loaded.");
trace(finalXML.triviaQuestion[0].answer1[0]);
questionBox.text = finalXML.triviaQuestion[0].question[0];
answerText1.text = finalXML.triviaQuestion[0].answer1[0];
answerText2.text = finalXML.triviaQuestion[0].answer2[0];
answerText3.text = finalXML.triviaQuestion[0].answer3[0];
answerText4.text = finalXML.triviaQuestion[0].answer4[0];
}
Update: I found the following to change the label, however I am confused as how I do this to buttons I have already created, perhaps using the instance name?
var myButton:Button = new Button();
myButton.label = "Click me";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,对于遇到同样问题的任何人...如果您有一个名为“answerBut1”的按钮实例,那么您可以执行以下操作:
Ok, for anyone who runs into the same problem...If you have a button instance with the name "answerBut1", then you can do the following:
是的,就是这样。我就是这么做的。但是,当我使用 Locale 更改语言时,我现在如何才能使其更加灵活 - 如何将数组中键的内容放入标签中?
例如
Yes, that's the way. It's how I do it. But however, how can I now make that more flexible, by when I use Locale to change languages - how do I put the contents of a key from the array into the label?
for example