2012-06-07 69 views
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> 

回答

3

你的代码来设置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> 

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

+0

非常感谢,我所有的代码似乎都能完美工作,只要我将它们包装在函数中。你的救星。我对node.js和javascript非常熟悉,并且认为我可以选择这种语言并使用它运行,nope,chuck testa。 –