2011-12-01 8 views
0

매우 기본적인 질문이 있습니다. 왜이 작동하지 않습니다! 정의되지 않은 속성의 액세스 : 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" 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> 

나는이 오류가 발생했습니다.

감사!

답변

5

구성 요소를 만들기 전에 텍스트를 설정하고 있습니다. 할당을 메서드에 넣고 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> 
+0

+1 감사합니다. – enloz