19 Replies Latest reply on Dec 2, 2006 8:46 AM by kglad

    dynamic text - am I doing something wrong

    SPGAnne Level 1
      I'm wondering if I'm doing something wrong here or this is just how stuff works. I have a movie clip (myClip_mc) which has a dynamic text field called myText_txt . The movie clip has a bunch of key frames where other stuff changes, but the myText_txt field appears on each of those frames. I set the myClip_mc.myText_txt.text = "Some Text Stuff". Then I do a myClip_mc.gotoAndStop("label") and the vaule of myClip_mc.myText_txt.text is blank and I need to reset it with another statement myClip_mc.myText_txt.text = "Some Text Stuff". Am I doing something wrong, or is this just the way it works. I would think since the name of the dynamic text field instance is the same in the movie clip that it would remember it's value even if I go to a new key frame.

      Thanks in advance to anyone willing to help me out.
        • 1. Re: dynamic text - am I doing something wrong
          abeall Level 3
          A keyframe is like a definition. So if you have a keyframe with the TextField in it as empty, then it will define the TextField when that keyframe is reached as having no text, even if you had applied text to it via AS.

          Solution is to place the TextField on a layer with no keyframes.

          HTH
          • 2. Re: dynamic text - am I doing something wrong
            SPGAnne Level 1
            Thank you for your helpful reply. I was using the movieclip frames to change some of the properties of the dynamic text field (color, etc.) I suppose it's a tradeoff of either refreshing the .text in actionscript v. setting the other properties in actionscript and not having to set the .text again. Hmmm, I'll have to think about that.

            BTW I visited your site as you had requested. Very creative. I have some more detailed comments. If you would like me to send via email, let me know where to send them.
            • 3. Re: dynamic text - am I doing something wrong
              abeall Level 3
              > I was using the movieclip frames to change some of the properties of the dynamic text field (color, etc.)
              I gotcha. So it was changing. Whenever I need to do this, there are two basic solutions I use:

              1) Rather than set the TextField.text property, use a variable on the MovieClip's timeline, say myText, and then set the TextField's Var property in the property inspector as myText(make sure the Var is set on all keyframes, since, like I said, each keyframe can completely redefine the object, so changing one keyframe will not affect the others). This way, the variable myText will stay the same and each keyframe of the TextField will pick it up.

              or 2) put the TextFIeld in a container MovieClip. You can then keyframe away with the MC and the contained TextField will not lost it's .text property.
              • 4. Re: dynamic text - am I doing something wrong
                SPGAnne Level 1
                Again, thank you so very much for your help. I'm a newbie as you can probably tell , and I am trying very hard to adopt good habits/practices up front. One thing that really concerns me about Flash is that it seems that code can be all over the place which will make debugging and maintaining stuff quite the challenge, so I'm trying not to scatter things all over the place. I understand your solution 1 which seems good, except I read in the Flash Help documentation that comes with Flash 8 Pro
                Working with Text > Controlling text with ActionScript > Setting dynamic and input text options
                "NOTE The Variable text box [in Properties] should be used only when authoring content for Flash Player 6 or earlier. " So it seems like Macromedia/Adobe doesn't want to support that in the long run.

                Your second solution, I'm not sure I understand. Are you saying I would have myClip_mc contain another clip called myTextClip_mc which in turn would have the dynamic text field myText_txt. If I set the color of the myText_txt field in the myTextClip_mc, won't that require a key frame in myTextClip_mc and make the problem appear again? (Sorry if I'm being a bit dense).

                Thank you very much for your patient help.
                • 5. Re: dynamic text - am I doing something wrong
                  abeall Level 3
                  > One thing that really concerns me about Flash is that it seems that code can be
                  > all over the place which will make debugging and maintaining stuff quite the
                  > challenge
                  You're right, code can potentially be all over the place. However, if you are careful, you can usually do everything with 1 frame of core AS, Classes, and maybe some scattered stop() commands. Between #include and AS2.0 classes, it's not too hard.

                  In reponse to the two solutions:
                  1) You're right, using the variable property for TextFields is not the most up to date way to do things, but it still works.

                  2) I think you got it, but it's possible I don't completely understand what the problem was. I hope I haven't lead you down a wrong path!

                  So, the way I understood your original setup, you had myClip_mc, which contained a multi-frame timeline. Part of it's timeline was myText_txt, and there were several keyframes that pertain to myText_txt.
                  What you described is correct: you put myText_txt in a MovieClip, myText_mc. You would then apply keyframes in myClip_mc to myText_mc, such as the Color adjustment that you can apply to all Symbols.

                  If you need to change actual TextField properties, such as font, alignment, textsize, then you'll need to do that via AS. CSS might help you there, as well, because then you could define the CSS styles all in one place, and simply swap the attached stylesheet.
                  • 6. Re: dynamic text - am I doing something wrong
                    SPGAnne Level 1
                    Sorry to be slow in my thank you to you. Got bogged down in another problem. At any rate, thank you. I think I get it. Hadn't thought about using the tint function of a movieclip to color text that is embedded in that clip. Aha. Unfortunately, it's not just color, it's also position and other stuff that I need to change on the text field, so looks like I'll have to stick to doing a "refresh" of the data in ActionScript. Just wanted to make sure I wasn't doing anything truly boneheaded.
                    • 7. Re: dynamic text - am I doing something wrong
                      abeall Level 3
                      No problem.

                      I'm sure you know what you're doing, but you could change the position with a MovieClip. Bu maybe you meant position as in text alignment or other text properties, such as kerning or leading.
                      • 8. Re: dynamic text - am I doing something wrong
                        Matulga
                        I think I'm running into the same problem that SPGAnne did. I tried what abeall suggested and it's not working. Here's my situation:

                        I have a movie clip called plotPoint_mc. It has two frames; the first has just a circle, and the second has a circle with a movie clip above. That movie clip is called plotPointText_mc, and it has a shaded rectangle with another movie clip on top of it. This third movie clip is called plotPointTextOnly_mc, and it only has a dynamic text box named plotVal_txt. (BTW, I started with all of these in the first movie clip--plotPoint_mc--but when that didn't work I tried what abeall suggested.)

                        The reason plotPoint_mc has two frames is because I have the circle by itself displayed unless there's a rollOver in which case it displays frame 2 until rollOut. This part works fine.

                        Here's the problem, I can't change the dynamic text. I tried giving each of the movie clips instance names, I've properly linked everything using identifiers with the same name as the movie clips, etc. but it just won't work. The frustrating part is that I have another movie clip I'm using (that consists of nothing but a dynamic text field) and I'm able to change that just fine.

                        There are many instances of plotPoint_mc on the stage at any given time, in case that makes any difference. They are given instance names of point1, point2, point3, etc.

                        I've tried using the instance names:
                        point1.plotPointText.plotPointTextOnly.plotVal_txt.text = "99";

                        using the clip names:
                        point1.plotPointText_mc.plotPointTextOnly_mc.plotVal_txt.text = "99";

                        and a bunch of other random stuff out of frustration:
                        point1.plotVal_txt.text = "99";
                        point1.text = "99";

                        Any help would be GREATLY appreciated! Thanks in advance! :-)

                        -Matulga
                        • 9. Re: dynamic text - am I doing something wrong
                          kglad Adobe Community Professional & MVP
                          attached to the timeline that contains your textfield place:

                          trace(this);

                          what you see in the output panel is the path to your textfield. prefix the instance name of your textfield with that and you should see your text (unless you've done something that requires embedded font, like masking, rotating etc).
                          • 10. Re: dynamic text - am I doing something wrong
                            Matulga Level 1
                            That's an excellent tip, kglad. Thank you. I'm sure I'll be using that idea for future problems! :-)

                            I put trace(this) on the only frame in the movie clip plotPointTextOnly_mc. When I did that, this is what I got for output:

                            _level0.point1.plotPointText.plotPointTextOnly

                            So, in my AS for the plotPoint_mc movie clip I wrote:

                            _level0.point1.plotPointText.plotPointTextOnly.plotVal_txt.text = "99";

                            It didn't work. :-( I'm not doing anything fancy with the text field. It's just a plain dynamic text field with no rotation, masking, etc. I've checked all of the obvious things like spelling errors, etc.

                            Any other suggestions?
                            • 11. Re: dynamic text - am I doing something wrong
                              Matulga Level 1
                              I should have mentioned, if I trace that value I get "undefined".

                              trace(_level0.point1.plotPointText.plotPointTextOnly.plotVal_txt.text);

                              Output is: undefined
                              • 12. Re: dynamic text - am I doing something wrong
                                kglad Adobe Community Professional & MVP
                                then you have either:

                                1. no textfield on _level0.point1.plotPointText.plotPointTextOnly with instance name plotVal_txt (check the instance name spelling and caps and if you think this is ok use trace(_level0.point1.plotPointText.plotPointTextOnly.plotVal_txt) to see if your textfield exists on that timeline.

                                or

                                2. yourtextfield has no text assigned to it.
                                • 13. Re: dynamic text - am I doing something wrong
                                  Matulga Level 1
                                  Wow! I just figured out the problem! I was re-reading a question I had posted on another forum back in February and it suddenly clicked. The person who had replied to my question said, "You cant set value to something that does not yet exist " That's it! I put the _level0.plotPoint1.plotPointText.plotPointTextOnly.plotVal_txt.text = "99"; code in the onRollOver event, AFTER the gotoAndStop(2); line and it worked! I hadn't even thought that it wouldn't exist UNTIL that frame had been visited.

                                  It's always the simplest things that are the hardest to find, isn't it?! :-)
                                  • 14. Re: dynamic text - am I doing something wrong
                                    Matulga Level 1
                                    Ok, I just ran into another problem. :-( Since that line is now inside the onRollOver function, I can't pass my for-loop counter value to it. Here's a simplified version of what I have:

                                    (dataValues is an array of numbers)

                                    for (var i:Number = 0; i < dataValues.length; i++) {
                                    point1.onRollOver = function () {
                                    this.gotoAndPlay(2);
                                    this.plotPointText.plotPointTextOnly.plotVal_txt.text = dataValues ;
                                    }
                                    }

                                    Since dataValues
                                    is inside the function, it doesn't have access to the counter from the for-loop. How do I pass that value into the function?
                                    • 15. Re: dynamic text - am I doing something wrong
                                      kglad Adobe Community Professional & MVP
                                      that code makes no sense. are you trying to define rollOver handlers for many buttons and not just point1?
                                      • 16. Re: dynamic text - am I doing something wrong
                                        Matulga Level 1
                                        Sorry, I was trying to keep things simple for the posting. In the loop the first line says:

                                        var currentPoint:String = "point"+i;

                                        and the rollOver code actually says:

                                        this[currentPoint].onRollOver etc.
                                        • 18. Re: dynamic text - am I doing something wrong
                                          Matulga Level 1
                                          Brilliant! That did it! Thank you for your help. :-)

                                          I had tried function (k:int = i) and dataValues[k] but apparently I can't use default function values in Flash Pro 8.

                                          Thanks again! :-)
                                          • 19. Re: dynamic text - am I doing something wrong
                                            kglad Adobe Community Professional & MVP
                                            you're welcome.

                                            your ith button has no way to remember it's the ith button unless you store the value of i in some variable that your ith button can access. storing the value of i in yourbutton.ivar allows just that.