• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 39483
  • Last Modified:

Change Dynamic Text Color Using Actionscript

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
kenfx
Asked:
kenfx
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Ramy_atefCommented:
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
 
Ramy_atefCommented:
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
 
Aneesh ChopraCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Aneesh ChopraCommented:
I mean to say, you only need to update the "sign_..." variable value to "1"  in text file..
0
 
kenfxAuthor Commented:
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
 
Aneesh ChopraCommented:
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
 
Ramy_atefCommented:
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
 
Ramy_atefCommented:
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
 
anjipCommented:
hi


please change ur varible name also to this.sign_*

or change in if condi as

if(sign_* == 1){}


regards
anjip
0
 
kenfxAuthor Commented:
Thanks Ramy_atef!

As soon as you pointed that out, I found the problem.
Just as you suspected.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now