Re: [Flashcoders] Converting hex colour numbers back and forth

2009-02-10 Thread ali drongo
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: ff
//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 
jason.merr...@bankofamerica.com wrote:

 Courtesy Evan Mullins of Circlecube Studio:

 //bitwise conversion of rgb color to a hex value
 function rgb2hex(r, g, b):Number
 {
return(r16 | g8 | b);
 }

 //bitwise conversion of a hex color into rgb values
 function hex2rgb (hex):Object
 {
var red = hex16;
var greenBlue = hex-(red16)
var green = greenBlue8;
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: flashcoders-boun...@chattyfig.figleaf.com
 [mailto:flashcoders-boun...@chattyfig.figleaf.com] 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..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
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Converting hex colour numbers back and forth

2009-02-10 Thread Juan Pablo Califano
The problem seems to be here:

var hexNum:Number = parseInt(c, 16);

You're asking parseInt to convert a string to an integer and telling it the
string is an hexadecimal representation, when it's decimal, according to
this line:

trace(string colour:+c); //  e.g. for red: 16711680

So try,

hexNum:Number = parseInt(c,10);

If you have a number, you don't need to worry about decimal / hexadecimal.
It's just a number: you can have, say, the number 10, which would be
represented as 10 in decimal, 0xa in hexadecimal, 1010 in binary, etc,
but those are just a way to display a number. If you already have the
number, you don't need any extra step.

Hope this helps.


Cheers
Juan Pablo Califano


2009/2/10, ali drongo alidro...@googlemail.com:

 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: ff
 //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 
 jason.merr...@bankofamerica.com wrote:

  Courtesy Evan Mullins of Circlecube Studio:
 
  //bitwise conversion of rgb color to a hex value
  function rgb2hex(r, g, b):Number
  {
 return(r16 | g8 | b);
  }
 
  //bitwise conversion of a hex color into rgb values
  function hex2rgb (hex):Object
  {
 var red = hex16;
 var greenBlue = hex-(red16)
 var green = greenBlue8;
 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: flashcoders-boun...@chattyfig.figleaf.com
  [mailto:flashcoders-boun...@chattyfig.figleaf.com] 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..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
  {
 

Re: [Flashcoders] Converting hex colour numbers back and forth

2009-02-10 Thread Muzak

Maybe this will help?
http://muzakdeezign.com/flex3/flex3lib/ColorUtil.zip

//docs
http://muzakdeezign.com/flex3/flex3lib/docs/com/muzakdeezign/flex/utils/ColorUtil.html

regards,
Muzak

- Original Message - 
From: ali drongo alidro...@googlemail.com

To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Monday, February 09, 2009 6:26 PM
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!).



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Converting hex colour numbers back and forth

2009-02-10 Thread Sidney de Koning

Hi Ali,

If you need to switch between different number systems, you can also  
try this:


var myUint:uint = 0xff; // this is the colour red

trace (myUint.toString(16)); //will trace ff -- in hexadecimal  
system;
trace (myUint.toString(2)); //will trace  --  
in binary system;


Hope this helps,

Sidney


On Feb 10, 2009, at 1:48 PM, Juan Pablo Califano wrote:


The problem seems to be here:

var hexNum:Number = parseInt(c, 16);

You're asking parseInt to convert a string to an integer and telling  
it the
string is an hexadecimal representation, when it's decimal,  
according to

this line:

trace(string colour:+c); //  e.g. for red: 16711680

So try,

hexNum:Number = parseInt(c,10);

If you have a number, you don't need to worry about decimal /  
hexadecimal.

It's just a number: you can have, say, the number 10, which would be
represented as 10 in decimal, 0xa in hexadecimal, 1010 in  
binary, etc,

but those are just a way to display a number. If you already have the
number, you don't need any extra step.

Hope this helps.


Cheers
Juan Pablo Califano


2009/2/10, ali drongo alidro...@googlemail.com:


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: ff
//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 
jason.merr...@bankofamerica.com wrote:


Courtesy Evan Mullins of Circlecube Studio:

//bitwise conversion of rgb color to a hex value
function rgb2hex(r, g, b):Number
{
  return(r16 | g8 | b);
}

//bitwise conversion of a hex color into rgb values
function hex2rgb (hex):Object
{
  var red = hex16;
  var greenBlue = hex-(red16)
  var green = greenBlue8;
  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: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] 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..com/text/test.php;;
request.method = 

Re: [Flashcoders] Converting hex colour numbers back and forth

2009-02-10 Thread ali drongo
Thanks everyone, Juan, you solved the final part of the puzzle and Muzak
thanks for your utility class it's very useful.
Cheers again!
Ali

On Tue, Feb 10, 2009 at 1:13 PM, Muzak p.ginnebe...@telenet.be wrote:

 Maybe this will help?
 http://muzakdeezign.com/flex3/flex3lib/ColorUtil.zip

 //docs

 http://muzakdeezign.com/flex3/flex3lib/docs/com/muzakdeezign/flex/utils/ColorUtil.html

 regards,
 Muzak

 - Original Message - From: ali drongo alidro...@googlemail.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Monday, February 09, 2009 6:26 PM
 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!).


 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Converting hex colour numbers back and forth

2009-02-10 Thread Taka Kojima
I usually don't use parseInt for this purpose I usually just cast it as a uint.

i.e.

uint(c);

would work as well.

glad you figured it out.

- Taka

On Tue, Feb 10, 2009 at 5:54 AM, ali drongo alidro...@googlemail.com wrote:
 Thanks everyone, Juan, you solved the final part of the puzzle and Muzak
 thanks for your utility class it's very useful.
 Cheers again!
 Ali

 On Tue, Feb 10, 2009 at 1:13 PM, Muzak p.ginnebe...@telenet.be wrote:

 Maybe this will help?
 http://muzakdeezign.com/flex3/flex3lib/ColorUtil.zip

 //docs

 http://muzakdeezign.com/flex3/flex3lib/docs/com/muzakdeezign/flex/utils/ColorUtil.html

 regards,
 Muzak

 - Original Message - From: ali drongo alidro...@googlemail.com
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Sent: Monday, February 09, 2009 6:26 PM
 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!).


 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Converting hex colour numbers back and forth

2009-02-09 Thread Mark Winterhalder
On Mon, Feb 9, 2009 at 6:26 PM, ali drongo alidro...@googlemail.com wrote:
 currColor = Number(0x+c);

I haven't looked into it in detail, but I think you would want to use
parseInt( 0x + c, 16 ) here.
If that doesn't fix it, try tracing the values throughout your
conversion and see where it breaks.

Mark
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Converting hex colour numbers back and forth

2009-02-09 Thread Merrill, Jason
Courtesy Evan Mullins of Circlecube Studio:

//bitwise conversion of rgb color to a hex value
function rgb2hex(r, g, b):Number 
{
return(r16 | g8 | b);
}

//bitwise conversion of a hex color into rgb values
function hex2rgb (hex):Object
{
var red = hex16;
var greenBlue = hex-(red16)
var green = greenBlue8;
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: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] 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..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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders