| By Jeff Tapper | Article Rating: |
|
| October 31, 2006 02:00 PM EST | Reads: |
11,955 |
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,955
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By 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: |
||||
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Adobe Flex Developer Earns $100K in New York City
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Ph.D. in Twitter Anyone?
- Eolas Sues the Internet
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Special Report on the Emerging Cloud Computing Trend
- Adobe Cans Another 9% of its Workforce
- My Thoughts on Ulitzer
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Ulitzer Live! New Media Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Executives Feature on Cloud Computing Expo Power Panel
- Software Flexibility in the Cloud - Part 4 of 5
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Where Are RIA Technologies Headed in 2008?
- 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
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe/Macromedia - Microsoft, Look Out!
- How To Create a Photo Slide Show ...
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- Has the Technology Bounceback Begun?
- "Real-World Flex" by Adobe's Christophe Coenraets






































