Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

changing dynamic text colors ??

New Here ,
Aug 20, 2007 Aug 20, 2007
In Flash 8, the dynamic text field instance name is energyLevel, as is the variable name associated with it. This field's text color was originally set to gold (outside of ActionScript). In the code, I'm trying to change it to red (without a condition at this point, just to see if it will work).

In the code prior to the init function:
energyLevel = 10;

I've tried Option 1: >>>>>>>>>>

newTextStyle = new TextFormat();
newTextStyle.color = "0xFF0000";
//
actor.onEnterFrame = function() {

energyLevel.setTextFormat(newTextStyle);

I've tried Option 2: >>>>>>>>>>>>>

actor.onEnterFrame = function() {

energyLevel.textColor = 0xFF0000;

And, I've tried Option 3: >>>>>>>>>>>>

actor.onEnterFrame = function() {

_root.energyLevel.textColor = 0xFF0000;

BUT, none work. This should be easy to do. Can anyone tell me what is wrong??

Thanks!




TOPICS
ActionScript
503
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 20, 2007 Aug 20, 2007
OK, first - do you have an instance name of 'energyLevel' assigned to the textField? Second you do not need to create a TextFormat just call:

energyLevel.textColor = 0xFF0000;

Also, you must have an MC with the instance name 'actor' that is instantiated on the timeline by the time you call the 'onEnterFrame' function.

I guessing you are missing the instance names.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 21, 2007 Aug 21, 2007
The suggestions you made had been done. After further tinkering (and using only .textColor as you suggested), I found that the problem was that the instance name needs to be different from the variable associated with field in the properties window (they had both been called energyLevel). Once I made one different, this worked. Thanks for your assistance along the way.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 21, 2007 Aug 21, 2007
PS: Since About Flash 6, I think most of us do not use the variables with text fields. It is much preferred to assign the .text property and just leave the var blank.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 21, 2007 Aug 21, 2007
For sure Rothrock, and you're welcome .Michael.

@Rothrock - btw did you see my last post at that other Q about the tab shortcut, just wanted to make sure, that you know those comments weren't directed your way 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 23, 2007 Aug 23, 2007
I understand what you both said about using .text instead of the variable, but what advantage does that give you? Just one less variable?

Also, if a dynamic text field holds a number and you need to do math periodically on that number, isn't it just easier to have:
amountLeft = amountLeft - (AmountFraction*.332)
vs.
amountLeftField.text = amountLeft - (AmountFraction*.332)
in which case you'd have another variable anyway?



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 23, 2007 Aug 23, 2007
not exactly, read: HERE

What if you are tracking a value that you don't want to display at the time, or want use it in other calculations. Also there are a few other ways to enter what you've got there, as in:

amountLeftField.text -= AmountFraction*.332;
amountLeftField.text *=.332;
amountLeftField.text /=1.332;
OR how about ...
a_txt.text -= f*.332;

Flash recognizes operations on a numerical value entry, performs the calc, and still displays as a String.

Additionally, if you use the underscore with an extention name for instance naming as in 'my_txt', Flash will recognize the extention and bring up a list of methods, properties and event handlers related to the data type when you type 'dot' after, if you have the 'code hints' preference turned on. Same with _mc, _btn, _ldr, _ti, _cb, ... etc. good for learning, and as you type the next few characters of the prop, the list will highlight the prop, and you can hit 'enter' to complete the rest, handy.

I'm not certain, but I believe that the TextField Var property has been eliminated entirely in AS3. (?)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 23, 2007 Aug 23, 2007
OK - thanks for your additional insight!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Aug 23, 2007 Aug 23, 2007
LATEST
you're welcome 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines