변환할 문자열을 uint actionscript/Flex
-
02-07-2019 - |
문제
내가 만드는 요소를 노출하려는 색상 속으로는 많은 플렉스 컨트롤 할 수 있는 말은 간단한 구성 요소는 다음과 같이,호출 할 수 있습 foo_label:
<mx:Canvas>
<mx:Script>
[Bindable] public var color:uint;
</mx:Script>
<mx:Label text="foobar" color="{color}" />
</mx:Canvas>
다음에 추가 구성 요소에서 다른 mxml 파일의 라인을 따라 뭔가:
<foo:foo_label color="red" />
때 나는 컴파일을 컴파일러는 불평:을 분석할 수 없습 값의 입력 단위에서 텍스트'red'.그러나 사용하면 일반 레이블을 할 수 있
<mx:Label text="foobar" color="red">
문제없이,색 숙박 시설은 여전히 유형 uint.
나의 질문은 어떻게 해 노출 공공할 수 있도록 제어하는 색상을 나의 구성 요소를 텍스트가 있습니까?왜 사용할 수 있는 문자열"red"로 uint 분야에 대한 mx 제어하지만 할 수가 없에서 동일한 사용자 정의 구성 요소가 필요한가요 뭔가 특별한가요?
감사합니다.
해결책
색상은 시설,그것은 스타일입니다.필요할 스타일을 정의합니다 다음과 같다:
[Style(name="labelColor", type="uint", format="Color" )]
(로 묶 태그를 정의할 경우 그것은에서 직접 MXML).당신은 다음을 추가 할 필요가 일부 ActionScript 이 처리하는 스타일을 적용하는 어느 당신을 제어해야를 참조하십시오 http://livedocs.adobe.com/flex/3/html/help.html?content=skinstyle_1.html 자세한 내용은.
다른 팁
여기에는 2 개의 내 utils 기능:
public static function convertUintToString( color:uint ):String {
return color.toString(16);
}
public static function convertStringToUint(value:String, mask:String):uint {
var colorString:String = "0x" + value;
var colorUint:uint = mx.core.Singleton.getInstance("mx.styles::IStyleManager2").getColorName( colorString );
return colorUint;
}
제휴하지 않습니다 StackOverflow