[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Change Dynamic Text Color Using Actionscript

Posted on 2006-05-22
10
Medium Priority
?
39,470 Views
Last Modified: 2011-08-18
I am using Flash 8 and I am building a flash stock ticker. I want to change the color of the text based on change of the stock (positive or negative). I have created a text file using aspx and I am loading the variables from that file (here's the sample output):

sym_0=ABP&trade_0=4.24&sign_0=0&change_0=-0.16&percent_0=-3.64&name_0=ABRAXAS PETRO (N&sym_1=AGII&trade_1=31.81&sign_1=0&change_1=-0.12&percent_1=-0.38&name_1=ARGONAUT GROUP IN&sym_2=ALG&trade_2=21.27&sign_2=0&change_2=-0.06&percent_2=-0.28&name_2=ALAMO GP INC&sym_3=CFR&trade_3=56.00&sign_3=0&change_3=-0.10&percent_3=-0.18&name_3=CULLEN FROST BNKR

I created a variable (sign_*) that denotes the change (0 = negative change, 1 = positive change).

Here's the code I have on my actions line of the movie, frame 1:

myData = new LoadVars();
myData.onLoad = function(){
   quote__0 = this.sym_0 + ": $" + this.trade_0 + ", " + this.change_0 + ", " + this.percent_0 + "% ";
   quote__1 = this.sym_1 + ": $" + this.trade_1 + ", " + this.change_1 + ", " + this.percent_1 + "% ";
   quote__2 = this.sym_2 + ": $" + this.trade_2 + ", " + this.change_2 + ", " + this.percent_2 + "% ";
   quote__3 = this.sym_3 + ": $" + this.trade_3 + ", " + this.change_3 + ", " + this.percent_3 + "% ";
   
               format = new TextFormat();
            format.color = 0x00FF00;
            
         if (this.sign_0 == 1) {
            tQuote_0.setTextFormat(format);
            };
       if (this.sign_1 == 1) {
            tQuote_1.setTextFormat(format);
            };
            if (this.sign_2 == 1) {
            tQuote_2.setTextFormat(format);
            };
            if (Number(this.sign_3) == 1) {
            tQuote_3.setTextFormat(format);
            };

};

myData.load("../stocks.txt");


All of the dynamic text boxes individual graphics, instances are given for each text box).
Everything works except changing the color of the font.

HELP!
0
Comment
Question by:kenfx
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16735867
Hi
You can use the HTML tag (font) in the dynamic text box
for example

myTextBox.htmlText = "<font color='#FF0000'>This is red text</font><font color='#0000FF'> This is blue text</font>";

that will display the text in different colors
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16736063
Forgot to tell you that myTextBox is the name of the text box instance (not the var)
also you have to clcik on "Render text as HTML" icon in the text box properties.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16736782
Hi,

nothing wrong with your code, just change "sign_0", "sign_1"... variables values to 1, color will be changed

because in your code you have specified the condition that color will be changed only if "sign_..." will be "1"

Rgds
Aneesh
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16736788
I mean to say, you only need to update the "sign_..." variable value to "1"  in text file..
0
 

Author Comment

by:kenfx
ID: 16742136
I've tried both suggestions.

The problem is that only the first item (tQuote_0) changes. The rest do not.
Any thing else I could do?
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16742229
It should depend on your textfile variables....

sign_1=1  means first textfield (tQuote_0) color will change

sign_2=1 means 2nd textfield (tQuote_1) color will also change

similarly for  3rd and 4th,

sign_3=1 and sign_4=1  will change the color of tQuote_2 and tQuote_3 textfields..

if still unable to fix it.. please upload your source file I will fix it for you

Rgds
Aneesh
0
 
LVL 7

Accepted Solution

by:
Ramy_atef earned 2000 total points
ID: 16742351
Hi
I've made you a flash file where everything is working fine, you can download it from:

www.pylon-group.com/tmp

Regard,
Ramy
0
 
LVL 7

Expert Comment

by:Ramy_atef
ID: 16742378
ps. i didn't change any of the your code..

I tihnk the problem in your file is that you didn't name the text boxes right .. please check that the name of the text boxes instance are : tQuote_0, tQuote_1 ,...  not the variables

open the FLA and you will understand me  :)
0
 
LVL 1

Expert Comment

by:anjip
ID: 16749003
hi


please change ur varible name also to this.sign_*

or change in if condi as

if(sign_* == 1){}


regards
anjip
0
 

Author Comment

by:kenfx
ID: 16756220
Thanks Ramy_atef!

As soon as you pointed that out, I found the problem.
Just as you suspected.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question