Question

So I am making a music visualizer and I am trying to set the linestyle for my graphics to be a pre defined color! But I get an error when trying

var lineColor:Color = new Color(120,120,12);
graphics.lineStyle(lineThickness, lineColor);

1067: Implicit coercion of a value of type fl.motion:Color to an unrelated type uint.

So then I tried

var lineColor:Color = new Color(120,120,12);
graphics.lineStyle(lineThickness, lineColor.color);

But lineColor.color always returns 0! What do I do? I can't believe there is no built in API to take a color object and make it a compatible hexadecimal uint for graphics!

Any help would be much apprectiated!

No correct solution

OTHER TIPS

Just use a method to return the hex value.

function get_uint_from_colour(red:int, green:int, blue:int) {

    return red << 16 | green << 8 | blue;

}

So in your example:

graphics.lineStyle(lineThickness, get_uint_from_colour(120, 120, 12));

In response to your comment about needing to use a set of pre-defined Color objects, you will still need to (at some point) convert them to the type uint as this is the accepted data-type for the lineStyle method.

My suggestion would be to adjust the get_uint_from_colour method to accept a Color object. Like so:

function get_uint_from_colour(colour:Color) {

    return int(colour.redMultiplier) << 16 | int(colour.greenMultiplier) << 8 | int(colour.blueMultiplier);

}

So in your code:

graphics.lineStyle(lineThickness, get_uint_from_colour(lineColor));

Please note that I have changed the name of my original method as I felt it better describes the function

Also, keep in mind that a Color object can hold much more information about itself than a standard Hex colour can - this superfluous information will be lost in the process of converting it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top