2010-04-26 2 views
0

"오류"상태를 정의하는 사용자 정의 TextInput 구성 요소를 만듭니다. errorString 속성의 길이가 0보다 큰 경우 상태를 "error"로 변경하기 위해 TextInput 클래스를 확장했습니다. 스킨 클래스에서 "오류"상태를 정의하고 크기 및 위치를 감지하는 논리를 추가했습니다. 오류 아이콘. 그러나 비트 맵 이미지 태그에서 "includeIn"속성을 사용하는 동시에이 코드를 사용하면 디자인보기 오류가 발생합니다. 어느 쪽이든 A) "includeIn"속성이 설정되지 않은 코드 만 포함하면 작동하거나 B) 아이콘 크기와 위치를 설정하는 코드를 포함하지 않고 "includeIn"속성 만 사용하면 작동합니다. "includeIn"속성과 아이콘 크기/위치 코드를 동시에 사용할 때 디자인보기 문제의 원인이 될 수있는 아이디어가 있습니까?Flash Builder 4 디자인보기 오류를 일으키는 "includeIn"속성

의 TextInput 클래스 :

 package classes { 

     import spark.components.TextInput; 

     public class TextInput extends spark.components.TextInput { 

      [SkinState("error")]; 

      public function TextInput() { 
       super();  
      } 

      override public function set errorString(value:String):void { 
       super.errorString = value; 
       invalidateSkinState(); 
      } 

      override protected function getCurrentSkinState():String { 

       if (errorString.length>0) { 
        return "error"; 
       } 

       return super.getCurrentSkinState(); 
      } 

     } 
    } 

의 TextInput 스킨 파일 : 그것에서의 상태가 활성화 될 때

플렉스 4에서
  override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void 
      { 
       //THIS IS THE CODE THAT SEEMS TO BE CAUSING THE PROBLEM 


       if(getStyle("iconSize") == "large") { 
        errorIcon.right = -12; 
        errorIcon.source = new errorIconLg(); 
       } else { 
        errorIcon.right = -5; 
        errorIcon.source = new errorIconSm(); 
       } 


       super.updateDisplayList(unscaledWidth, unscaledHeight); 
      } 
     </fx:Script> 

     <s:states> 
      <s:State name="normal"/> 
      <s:State name="disabled"/> 
      <s:State name="error"/> 
     </s:states> 



     //If I remove the problem code above or if I take out the includeIn 
     //property here, it works 

     <s:BitmapImage id="errorIcon" verticalCenter="0" includeIn="error" /> 


    </s:SparkSkin> 

답변

1

가 구성 요소 만 인스턴스화됩니다. 따라서 스킨이 처음로드 될 때 errorIcon은 null 참조입니다. 인스턴스화는 오류 상태가 활성화 될 때까지 지연됩니다. 즉시 인스턴스화하기 위해 itemCreationPolicy = "immediate"속성을 설정합니다.

<s:BitmapImage id="errorIcon" 
       source="../images/error.png" 
       itemCreationPolicy="immediate" 
/>