0

我有一个如下的 mxml 应用程序。如何从 actionscript 文件中更改标签文本?

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="initApp()">
    <fx:Script>
        <![CDATA[
            public function initApp(){
                var p = new my_player("a");
            }
        ]]>
    </fx:Script>
    <s:Label x="700" y="409" text="Label" id="lble" width="131" height="41"/>
</s:Application>

my_player.as 代码

package 
{
    import spark.components.Label;
    public class my_player
    {
        public var lble:Label;
        public function my_player(a:String)
        {
            lble.text="hello";
        }
    }
}
4

2 回答 2

0

使用构造函数将标签从主应用程序注入到传送播放器(另一种方式 - 绑定)

public function initApp(){
    var p = new my_player("a", lble);
}

public function my_player (a:String, targetLabel:Label)
{
    lble = targetLabel;
    lble.text="hello";
}
于 2013-02-27T14:58:49.487 回答
0

你不需要第二节课:(

<?xml version="1.0" encoding="utf-8"?>
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    creationComplete="initApp()">
    <fx:Script>
        <![CDATA[
        public function initApp(){

            // access your components by id
            lble.text  = "My new text for the label"
        }
        ]]>
    </fx:Script>
    <s:Label x="700" y="409" text="Label" id="lble" width="131" height="41"/>
</s:Application>
于 2013-02-28T14:37:06.143 回答