8 Replies Latest reply on Aug 23, 2007 9:13 PM by clbeech

    changing dynamic text colors ??

    .Michael.
      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!




        • 1. Re: changing dynamic text colors ??
          clbeech Level 3
          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.
          • 2. Re: changing dynamic text colors ??
            .Michael. Level 1
            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.
            • 3. Re: changing dynamic text colors ??
              Rothrock Level 5
              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.
              • 4. Re: changing dynamic text colors ??
                clbeech Level 3
                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 :)
                • 5. Re: changing dynamic text colors ??
                  .Michael. Level 1
                  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?



                  • 6. Re: changing dynamic text colors ??
                    clbeech Level 3
                    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. (?)
                    • 7. Re: changing dynamic text colors ??
                      .Michael. Level 1
                      OK - thanks for your additional insight!
                      • 8. Re: changing dynamic text colors ??
                        clbeech Level 3
                        you're welcome :)