2010-02-13 5 views
1

내 AS3 클래스 내에서 나는 this.width을 호출하고, 객체의 내용이 주어지면 불가능한 경우에도 반환하는 값은 항상 1입니다.클래스 내의 this.width는 항상 동일한 값을 반환합니다.

AS3의 표준 동작입니까?

간단한 클래스 버전이 아래에 게시됩니다. 간단한 육각형 만 포함 된 MovieClip 심볼에 연결됩니다.

package { 

    import flash.display.*; 
    import flash.utils.*; 
    import flash.events.*; 

    public class Hexagon extends MovieClip 
    { 
     var startWidth:Number; 
     var startHeight:Number; 

     public function Hexagon() 
     { 
      var myTimer:Timer = new Timer(2000); 
      myTimer.addEventListener(TimerEvent.TIMER, timerFunction); 
      myTimer.start(); 

      startWidth = this.width; 
      startHeight = this.height; 

      trace("startWidth:" + " " + startWidth); 
      trace("startHeight:" + " " + startHeight); 
     } 

     function timerFunction (evt:TimerEvent):void 
     { 

     } 
    } 
} 
+0

문제는 당신이 실버 라이트를 사용하지 않을 것입니다 랜스. –

+0

당신은 어떤 과목을 확장합니까? 아마도 간단한 버전을 게시 할 수 있습니다. 문제가 무엇인지 알기가 어렵습니다. –

+0

MovieClip을 확장합니다. 나는 원래의 질문에 단순화 된 코드를 포함하도록 권고했다. – cmal

답변

0

예 이것은 당신이 재산/접근 설정이 설정되지 않습니다 지적되는 생성자의 폭과 높이를 요구하고 있기 때문에 그것의, 표준입니다. 속성이 공식적으로 설정 될 때까지 기다리십시오. 가장 안정적으로 Event.ADDED_TO_STAGE을 따르십시오. 이것은 나를 위해 노력하고 있습니다 :

package 
{ 
    import flash.display.*; 
    import flash.events.*; 
    import flash.utils.*; 

    public class Movie extends MovieClip 
    { 
     public var startWidth:Number; 
     public var startHeight:Number; 

     public function Movie() 
     { 
      var myTimer:Timer = new Timer(2000); 
      myTimer.addEventListener(TimerEvent.TIMER, timerFunction); 
      myTimer.start(); 

      startWidth = this.width; 
      startHeight = this.height; 

      trace("startWidth:" + " " + startWidth); 
      trace("startHeight:" + " " + startHeight); 
      addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler); 
     } 

     public function addedToStageHandler(event:Event):void 
     { 
      startWidth = this.width; 
      startHeight = this.height; 

      trace("new startWidth:" + " " + startWidth); 
      trace("new startHeight:" + " " + startHeight); 
     } 

     public function timerFunction(evt:TimerEvent):void 
     { 

     } 
    } 
} 

가 도움이 알려줘,

관련 문제