David Harris's Technology Blog

ColdFusion, Flex, and other stuff...   (and 366,137 hours, 24 mins in to my plan for global domination)

Search:

Calendar:

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Subscribe:

Enter your email address to subscribe to this blog.

Archives By Subject:

Tags:

action script adobe air ajax cfug coldfusion flash flex frameworks free software fxug general jpgmetadatareader mac off topic opensource papervision spry

Recent Entries:

No recent entries.

Top Posts:

Recent Comments:

Top Commenters:

My Links:

RSS:


Getting Red from my color

I have a situation where I want to manipulate colors in flash.

The idea is that the colors will cross fade nicely from one shade to another.

While you can define colors like this: 0xef556ef

that is stored as a unit data type.

Looking at the above string, it's 8 char in length.

The first two "0x" tell flash to treat this string as a hexadecimal value.

the next two "ef" are the red value, the next two "55" are green and the last 2 "ef" are blue.

Given the above value, I wanted to get the red shade of it, and only the red shade.

This is what I came up with:

var myColor       : uint = 0xef556ef

//convert the color to a string on a hex base and get the first 2 chars with "0x" at the front
var redValueString   :String = "0x" + myColor.toString( 16 ).substr(0,2);
            
trace( redValueString );

//convert the sting to the int value
var redValueInt      : int = int( redValueString );
            
trace( redValueInt.toString() );

This does give me the result, which is good, but I'm no flash pro, so is there a better (right?) way to do it?

Feel free to tell me if there is!

Simple Example of Randomizing the order of an array in ActionScript

Just got asked this by a work mate and after asking Mr Google and looking at the Array Documentation came up with this (Flex based) example, so thought I would share :-)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
>

<mx:Script>
<![CDATA[
private function myExample() : void
{
//can be an array of anything you like, but using letters here
var myArray   : Array   = ( "a,b,c,d,e,f,g,h,j,k,l" ).split(",");

//sort the array using my function
myArray.sort( myFunction );

debug.text = myArray.toString() + "\n" + debug.text;
}

//This function takes in 2 args, but we never use them...
private function myFunction( a : Object , b : Object ) : int
{
return ( Math.round( Math.random() * 10 ) - 5);// return a random value above, below or on 0 }
]]>
</mx:Script>

<mx:Button
label="Make me Random"
click="myExample();"
/>


<mx:TextArea
id   = "debug"
height="100%"
/>


</mx:Application>