| By Jeff Tapper | Article Rating: |
|
| October 31, 2006 02:00 PM EST | Reads: |
11,656 |
It's really convenient for anyone coming from an HTML background that we can now provide colors to Flex using html standard syntax for hexidecimal number (#000000 = black, #ffffff= white, etc). I've recently been building some tools to convert drawings in the flash player to and from SVG format. SVG, like HTML, likes to specify hexidecimal numbers with a "#" prefix, but the flash player drawing API needs hexidecimal numbers to be prefixed with "0x" To help migrate back and forth between hexStrings and AS numbers, I wrote a few static methods, which are working well for me:
package utils {
public class Colors {
public static function hexStringToNumber(hexStr:String):Number{
if(hexStr.length != 7){
return -1;
}
if(hexStr.charAt(0) != "#"){
return -1;
}
var newStr:String = hexStr.substr(1,6);
var numStr:String = "0x"+newStr;
var num:Number = Number(numStr);
return num;
}
public static function numToHexString(num:Number):String{
var hexStr:String = num.toString(16);
while(hexStr.length < 6){
hexStr = "0"+hexStr;
}
hexStr = "#"+hexStr;
return hexStr;
}
}
}
As you can see, there are 2 methods hexStringToNumber and numToHexString. These can be used simply like this:
var whiteNum:Number = Colors.hexStringToNumber ("#ffffff");
var whiteStr:String = Colors.numToHexString(16777215);posted Tuesday, 31 October 2006
tags: flex2 as3 svg hexidecimal
links: digg this del.icio.us technorati reddit
Published October 31, 2006 Reads 11,656
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
About Jeff Tapper
Jeff Tapper, co-founder of Tapper, Nimer and Associates, is an Editorial Board member of Web Developer's & Designer's Journal. He has been developing Internet-based applications since 1995, for a myriad of clients including Toys R Us, IBM, Allaire, Dow Jones, American Express, M&T Bank, Verizon, Allied Office Supplies, and many others. As an Instructor, he is certified to teach all of Adobe's courses on Flex, ColdFusion and Flash development. He has worked as author and technical editor for several books on technologies including Flex, Flash and ColdFusion, such as "Object Oriented Programming with ActionScript 2.0", and "Flex 2 Training from the Source."
![]() |
Web Developer's & Designer's Journal 10/31/06 11:01:42 AM EST | |||
It's really convenient for anyone coming from an HTML background that we can now provide colors to Flex using html standard syntax for hexidecimal number (#000000 = black, #ffffff= white, etc). I've recently been building some tools to convert drawings in the flash player to and from SVG format. SVG, like HTML, likes to specify hexidecimal numbers with a '#' prefix, but the flash player drawing API needs hexidecimal numbers to be prefixed with '0x' To help migrate back and forth between hexStrings and AS numbers, I wrote a few static methods, which are working well for me: |
||||
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Java Kicks Ruby on Rails in the Butt
- Ulitzer’s Amazing First 30 Days in Public Beta
- SYS-CON's "Government IT Expo" to Highlight Cloud Computing and SOA
- Will Ulitzer Dominate News Content on The Web? -Gartner
- Clear Toolkit 4: The Road Map
- Creating Adobe AIR Native Menu with Flash CS4
- Menu Interaction in Adobe AIR
- The Darker Sides Of Cloud Computing: Security and Availability
- Adobe AIR: Creating Dock and System Tray Icon Menus
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Creating PDF Documents from Flex Applications
- Java Kicks Ruby on Rails in the Butt
- WebORB Launched for Flex, Flash, AJAX and Silverlight
- Adobe Takes LiveCycle into the Cloud
- Ulitzer’s Amazing First 30 Days in Public Beta
- Adobe Creates a Sandbox in the Sky
- AJAX and RIA Market Is Heating Up: Sun CEO
- SYS-CON's "Government IT Expo" to Highlight Cloud Computing and SOA
- The Role of an RIA in the Enterprise
- Cover Story: How to Increase the Frame Rates of Your Flash Movies
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Your First Adobe Flex Application with a ColdFusion Backend
- Adobe Flex 2: Advanced DataGrid
- Adobe/Macromedia - Microsoft, Look Out!
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- How To Create a Photo Slide Show ...
- "Real-World Flex" by Adobe's Christophe Coenraets








































