2 Replies Latest reply on Nov 1, 2006 9:47 AM by TimSymons

    Actionscript for Dynamic Text

    ChuckRWD
      I am designing my first flash site, and created a Dynamic text field called header_txt. I want the content inside this field changed based on which page the user navigates to. I have used an "IF" statement inside a Declared Function , but wonder if that is the best option, also, my IF statement is no working. Here it is:

      function headingChange() {
      if (_root._currentframe == "contact") {
      header_txt.text = "Contact Us";
      } else if (_root._currentframe == "about") {
      header_txt.text = "About Us";
      }
      }
      headingChange();

      var header_txt:String = "";

      Why is this not working, and what would be a better way of changing this field?

      Thanks for the help!

      Chuck


        • 1. Re: Actionscript for Dynamic Text
          TimSymons Level 1
          _currentframe only returns a number. You can't access the frame's label with actionscript, except to specify it as a parameter in the gotoAndPlay() method.

          I would assume that you are calling the headingChange() function at each labeled frame. If you are, then just change the function call to this:

          At frame labeled "contact": headingChange("contact");

          At frame laveled "about": headingChange("about");

          Change your function to read as follows:

          function headingChange(s:String) {
          if (s== "contact") {
          header_txt.text = "Contact Us";
          } else if (s== "about") {
          header_txt.text = "About Us";
          }
          }

          Or, you could just access your dynamic textfield directly everytime you get to a new frame with a label by executing the following code in a frame:

          At the frame labeled "about": header_txt.text = "About Us";

          Either way would work. Though I like keeping stuff like this in a function. It makes it easier to update so that it does more in the future.



          Tim
          • 2. Re: Actionscript for Dynamic Text
            TimSymons Level 1
            Also, just noticed that you should delete this line:

            var header_txt:String = "";


            or change it to read:


            header_txt.text = "";


            Since you said that "header_txt" was the name of you dynamic textfield, don't use that same name for a variable too.


            Tim