如何在Flash中使用AS3动态更改按钮标签?

发布于 2024-11-04 05:58:32 字数 1012 浏览 0 评论 0原文

我可以运行下面的代码,其中答案是悬停在按钮上的动态文本框。但是,用户无法单击文本框与其重叠的按钮。我需要一种方法来分配按钮标签(如下面的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

攒一口袋星星 2024-11-11 05:58:32

好的,对于遇到同样问题的任何人...如果您有一个名为“answerBut1”的按钮实例,那么您可以执行以下操作:

var myButton:Button = new Button();
myButton = answerBut1;
myButton.label = "Click me";

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:

var myButton:Button = new Button();
myButton = answerBut1;
myButton.label = "Click me";
葬花如无物 2024-11-11 05:58:32

是的,就是这样。我就是这么做的。但是,当我使用 Locale 更改语言时,我现在如何才能使其更加灵活 - 如何将数组中键的内容放入标签中?

btnGPS.label = Locale.loadString("IDS_001");

例如

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?

btnGPS.label = Locale.loadString("IDS_001");

for example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文