A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: color conversion object to uint

  1. #1
    Senior Member
    Join Date
    Feb 2000
    Posts
    226

    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!

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    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 ) );
    }

  3. #3
    Senior Member
    Join Date
    Feb 2000
    Posts
    226
    Thanks, Works well now!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center