在标签中设置文本

时间:2012-06-07 00:11:56

标签: flex actionscript flexbuilder

这应该是超级简单但我不能为我的生活似乎只是在运行时设置标签的文本。它抛出“1120:访问未定义的属性lbl_param”

<?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"
               width="398" height="85" minWidth="398" minHeight="85">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label id="lbl_param" x="19" y="10" width="105" height="29" text="Paramaters: "/>

    <fx:Script>
        <![CDATA[
            lbl_param.text = "test113";
        ]]>
    </fx:Script>
</s:Application>

1 个答案:

答案 0 :(得分:4)

设置lbl_param.text的代码应该在一个方法中:脚本块中唯一可以在方法之外运行的代码是类导入或变量定义。此示例将代码放在初始化事件处理器中:

<?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"
               width="398" height="85" minWidth="398" minHeight="85" initialize="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label id="lbl_param" x="19" y="10" width="105" height="29" text="Paramaters: "/>

    <fx:Script>
        <![CDATA[
           public function init():void{
            lbl_param.text = "test113";
           }
        ]]>
    </fx:Script></s:Application>

免责声明:我在浏览器中编写了这段代码,它可能不是“编译器”完美的。

相关问题