2012-06-07 67 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。 –