Go Back   kirupaForum > Flash > ActionScript 1.0/2.0

Reply
 
Thread Tools Display Modes
Old 11-06-2009, 06:41 AM   #1
revo999
Registered User
change color of string

var mystr:String;

how i can apply random colors to "mystr" string ?
in as2
revo999 is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-06-2009, 07:13 AM   #2
Swooter
Swooter - AS/JS/HTML/CSS
 
Swooter's Avatar
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
Swooter is offline   Reply With Quote
Old 11-06-2009, 07:43 AM   #3
revo999
Registered User
this just tracing the random color value

but how i can apply this to A STRING
revo999 is offline   Reply With Quote
Old 11-06-2009, 07:50 AM   #4
wkt
Registered User
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..
wkt is offline   Reply With Quote
Old 11-06-2009, 09:07 AM   #5
glosrfc
Registered User
 
glosrfc's Avatar
Location Halley Research Station, Latitude 75°35' S, Longitude 26°39' W, Brunt Ice Shelf, Coats Land, Antarctica

Posts 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
glosrfc is offline   Reply With Quote
Old 11-06-2009, 09:54 AM   #6
revo999
Registered User
THANK YOU glosrfc
revo999 is offline   Reply With Quote
Old 11-06-2009, 09:56 AM   #7
Swooter
Swooter - AS/JS/HTML/CSS
 
Swooter's Avatar
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
Swooter is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:28 AM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com