|
-
color conversion object to uint
Hi,
I am trying to set selectedColor of the colorPicker component to the color of a TextFormat. colorPicker.selectedColor is of type uint and TextFormat.color of type object. I looked around and found this function:
Code:
function fixColorCode( color:Object, hasAlpha:Boolean = false ):uint
{
if( color is String ){
var pattern:RegExp = /#/;
color = uint( color.toString().replace( pattern,"0x" ) );
}else if( !( color is Number ) ){
color = Number( color );
}
var max:Number = ( hasAlpha ) ? 0xFFFFFFFF : 0xFFFFFF;
return uint( Math.min( Math.max( color, 0 ), max ) );
}
The last line returns the following error: "1118: Implicit coercion of a value with static type Object to a possibly unrelated type Number."
Anyone knows how to do this?
Thanks!
-
Code:
function fixColorCode( color:Object, hasAlpha:Boolean = false ):uint {
if (color is String) {
var pattern:RegExp=/#/;
color=uint(color.toString().replace(pattern,"0x"));
} else if ( !( color is uint ) ) {
color=uint(color);
}
var max:uint = ( hasAlpha ) ? 0xFFFFFFFF : 0xFFFFFF;
return uint( Math.min( Math.max( color as uint, 0 ), max ) );
}
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|