Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 使用ActionScript更改标签文本_Actionscript 3_Apache Flex_Actionscript - Fatal编程技术网

Actionscript 3 使用ActionScript更改标签文本

Actionscript 3 使用ActionScript更改标签文本,actionscript-3,apache-flex,actionscript,Actionscript 3,Apache Flex,Actionscript,我有一个非常基本的问题。为什么这不起作用 <?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"

我有一个非常基本的问题。为什么这不起作用

<?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="1000" height="550" minWidth="960" backgroundColor="#F2F0F0">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label id="test1" x="43" y="259" text="Label"/>

    <fx:Script>
        <![CDATA[
            test1.text = "Yay! This works...!";
        ]]>
    </fx:Script>
</s:Application>

我遇到此错误:访问未定义的属性。


谢谢

在创建组件之前设置文本。尝试将分配放入方法并在creationComplete上调用该方法:

<?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="1000" height="550" minWidth="960" backgroundColor="#F2F0F0" 
           creationComplete="onCreationComplete()">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="test1" x="43" y="259" text="Label"/>

<fx:Script>
    <![CDATA[
        public function onCreationComplete():void {
            test1.text = "Yay! This works...!";
        }
    ]]>
</fx:Script>
</s:Application>

您正在创建组件之前设置文本。尝试将分配放入方法并在creationComplete上调用该方法:

<?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="1000" height="550" minWidth="960" backgroundColor="#F2F0F0" 
           creationComplete="onCreationComplete()">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="test1" x="43" y="259" text="Label"/>

<fx:Script>
    <![CDATA[
        public function onCreationComplete():void {
            test1.text = "Yay! This works...!";
        }
    ]]>
</fx:Script>
</s:Application>