Thanks for your responses guys. I'm still stuck on this and I have been
playing around a lot. I can get the number from the decimal format to the
hex string but when I try to convert it to a hex number the colour is
incorrect.
Any advice much much appreciated, this is taking up lots of time.
Thanks:
public function colorIn(o:Object):void
{
trace("===================");
var colA:Array = o.Colors.split(",");
colA.splice(0,1);
for ( var i:uint=1; i<=totSprites-1; i++ ) {
var c:String = colA[i];
trace("string colour:"+c); // e.g. for red: 16711680
//convert to decimal number
var tmpN:Number = Number(c);
trace("decimal:"+tmpN); // traces: 16711680
//convert to string of hex number
var hexStr:String = tmpN.toString(16);
trace("hexStr:"+hexStr); //traces: ff0000
//convert to hex number
var hexNum:Number = parseInt(c, 16);
trace("= = = = = = => hex number:"+hexNum); //traces in decimal format and
wrong number: 376510080
//set mc to color
var mcToCol:* = mainImage["s"+i];
//transform color
var newColorTransform:ColorTransform = mcToCol.transform.colorTransform;
newColorTransform.color = hexNum;
mcToCol.transform.colorTransform = newColorTransform;
};
}
On Mon, Feb 9, 2009 at 8:55 PM, Merrill, Jason <
[email protected]> wrote:
> Courtesy Evan Mullins of Circlecube Studio:
>
> //bitwise conversion of rgb color to a hex value
> function rgb2hex(r, g, b):Number
> {
> return(r<<16 | g<<8 | b);
> }
>
> //bitwise conversion of a hex color into rgb values
> function hex2rgb (hex):Object
> {
> var red = hex>>16;
> var greenBlue = hex-(red<<16)
> var green = greenBlue>>8;
> var blue = greenBlue - (green << 8);
> //trace("r: " + red + " g: " + green + " b: " + blue);
> return({r:red, g:green, b:blue});
> }
>
>
>
> Jason Merrill
>
> Bank of America
> Learning Performance Solutions Instructional Technology & Media
>
> Learn about the Adobe Flash platform for rich media experiences - join
> the Bank of America Flash Platform Community
>
>
>
>
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of ali
> drongo
> Sent: Monday, February 09, 2009 12:26 PM
> To: Flash Coders List
> Subject: [Flashcoders] Converting hex colour numbers back and forth
>
> Hi there, I'm saving a bunch of colours as a string then using this
> string
> later to colour objects in the same way. Something is going wrong
> though as
> the colours I am getting back are not the same as the ones I put in.
> If anyone could point out where I'm going wrong I'd be really grateful,
> I've
> googled this and and have checked the help files and as far as I can see
> it's correct (though obviously it isn't!).
>
> Here's my code, I've written comments next to the relevant lines:
>
> /// in my coloured button class
>
>
> // 1) colour is set on mouse click
> private function clickHandler(e:MouseEvent):void
> {
> // passes hexValue from ColorPicker
> colorThis(this.parent.parent["colorPick"].hexValue);
> }
> // 2) color is stored in var
> public function colorThis(c:String):void
> {
> //stores colour
> currColor = Number("0x"+c);
> var newColorTransform:ColorTransform = this.transform.colorTransform;
> newColorTransform.color = currColor;
> this.transform.colorTransform = newColorTransform;
> }
>
>
>
> // application class
> // 3) stores colors in an array
> private function collectColors():Array
> {
> colors_ar = new Array();
> for ( var i:uint=1; i<=totSprites; i++ ) {
> //stores colour in array
> colors_ar[i] = mainImage["s"+i].currColor;
> };
> return colors_ar;
> }
>
> // 4) array is written to string and sent to php to be written to txt
> file
>
> private function sendData(e:MouseEvent):void
> {
> showSending(true);
> var variables:URLVariables = new URLVariables();
> //stores all colours as a string
> variables.colors = collectColors().toString();
> var request:URLRequest = new URLRequest();
> request.url = "http://www.xxxx.com/text/test.php";
> request.method = URLRequestMethod.POST;
> request.data = variables;
> var loader:URLLoader = new URLLoader();
> loader.dataFormat = URLLoaderDataFormat.TEXT;
> loader.addEventListener(Event.COMPLETE, completeHandler);
> try
> {
> loader.load(request);
> }
> catch (error:Error)
> {
> trace("Unable to load URL");
> }
> }
>
>
> ///////// viewer class
> // 5)
>
> public function colorIn(o:Object):void
> {
> var colA:Array = o.Colors.split(",");
> colA.splice(0,1);
> for ( var i:uint=1; i<=totSprites; i++ ) {
> //calls the method in the coloured button class
> mainImage["s"+i].colorThis(colA[i]).toString(16);
> };
> }
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders