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 に答える