11-06-2009, 06:41 AM
|
#1
|
|
|
change color of string
var mystr:String;
how i can apply random colors to "mystr" string ?
in as2
|
|
|
11-06-2009, 07:13 AM
|
#2
|
|
|
ActionScript Code:
var $hex:Array = [0,1,2,3,4,5,6,7,8,9,0,"A","B","C","D","E","F"]; function randomColor():String { var $temp:String = String($hex[Math.floor(Math.random() * 17)]); $temp += String($hex[Math.floor(Math.random() * 17)]); $temp += String($hex[Math.floor(Math.random() * 17)]); $temp += String($hex[Math.floor(Math.random() * 17)]); $temp += String($hex[Math.floor(Math.random() * 17)]); $temp += String($hex[Math.floor(Math.random() * 17)]); return "0x" + $temp; } trace(randomColor());
__________________
AS / JS / HTML / CSS / PHP
|
|
|
11-06-2009, 07:50 AM
|
#4
|
|
|
Well, you can put your text box into a movieclip and use setRGB in the Color class on it, I reckon.
edit: more info below
ActionScript Code:
var mycolor:Color = new Color(_root.myBox);
mycolor.setRGB(0x678432);
_root.myBox.setTransform(mycolor);
This paints a square I created called "myBox" in a sick green color. And it works fine if you put a text box into the movieclip.
Last edited by wkt; 11-06-2009 at 08:01 AM..
|
|
|
11-06-2009, 09:07 AM
|
#5
|

 |
Halley Research Station,
Latitude 75°35' S,
Longitude 26°39' W,
Brunt Ice Shelf,
Coats Land,
Antarctica |
|
 |
4,154 |
|
|
ActionScript Code:
var myStr:String = "this is the string I want to colour"; var my_fmt:TextFormat = new TextFormat(); my_fmt.color = Math.round(Math.random() * 0xFFFFFF); this.createTextField("my_txt", 1, 100, 100, 300, 100); my_txt.text = myStr; my_txt.setTextFormat(my_fmt);
__________________
©2006 GlosRFC - Searching 8,168,684,336 brain cells
|
|
|
11-06-2009, 09:56 AM
|
#7
|
|
|
Quote:
|
Math.round(Math.random() * 0xFFFFFF);
|
Sweet, didn't know that... I knew that a Number could be a 0x value, but it's good to know you can use it in Math classes aswell.
__________________
AS / JS / HTML / CSS / PHP
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 11:28 AM.
|
|