0

这应该非常简单,但我似乎无法在运行时设置标签的文本。它抛出“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>
4

1 回答 1

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>

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

于 2012-06-07T01:14:58.977 回答