10 Replies Latest reply on Apr 17, 2006 10:44 AM by abeall

    Change dynamic text var with onRelease

    jondro
      Hello...
      Im trying to change the var of a dynamic text field when a button is pressed. The var needs to be changed in order to load the text from one text file(news.txt) to another(carshow.txt). I've tried a couple different things but my coding skills are not that good. Here is what I have tried. I have a textfield with the var set to "news" and two buttons but1 and but2.

      The actions in but1 are :
      on(release){
      var.textfield="news"
      }

      and but2:

      on(release){
      var.textfield="carshow"
      }

      The actions in the main are:

      loadVariablesNum("news.txt", 0);
      loadVariablesNum("carshow.txt", 0);

      Any ideas???
        • 1. Re: Change dynamic text var with onRelease
          abeall Level 3
          What made you try that? If you look up TextField in the user reference you find it has a property 'variable' or 'text' which is what you want:

          on(release){
          myTextfield.variable = _root.news;
          }

          ...assuming that loadVariablesNum("news.txt", 0); is loading "&news=whatever"

          Also, you can probably consolidate your loadVariablesNum calls into one:

          "&news=bla blah blah&carshow=yadda yadaa yaada"
          • 2. Re: Change dynamic text var with onRelease
            jondro Level 1
            Thanks abeall for your help I made the changes that you recommended but it still doesnt work. Now when I click on the buttons it just erases the text entirely and doesnt show anything in the text box. Here is the actionscript I used...

            but1:

            on(release){
            textfield.variable = _root.news;
            }

            but2:

            on(release){
            textfield.variable = _root.carshow;
            }

            Your assumption that loadVariablesNum("news.txt", 0); is loading "&news=whatever" is correct and both &news and &carshow work when I change the var of the textfield manually.

            Any ideas why it still doesnt work?
            • 3. Change dynamic text var with onRelease
              abeall Level 3
              I wouldn't name your TextField 'textfield', try giving it a more descriptive name with a _txt suffix. The suffix is just for readability, but 'TextField' is a reserved word in AS. Perhaps 'content_txt'.

              If you do this:
              on(release){
              trace(_root.news);
              trace(content_txt);
              content_txt.text = _root.news;
              }

              What do you get? Erasing the text sounds like the variable _root.news is not defined, or not defined properly. After your loadVariablesNum() command put:
              onData = function(){
              for(var i in this){
              trace(i+" = "+this[ i ]);
              }
              }
              And let me know what it outputs.
              • 4. Re: Change dynamic text var with onRelease
                jondro Level 1
                Thanks again! I think we almost got it but it still doesnt work entirely. Here is the output that you requested:

                • 5. Re: Change dynamic text var with onRelease
                  abeall Level 3
                  Hm. Based on that output, then this should have worked:

                  on(release){
                  content_txt.variable = _root.news;
                  }

                  But are but1 and but2 MovieClip symbols, or Button symbols? If there are MovieClip buttons, you'll need:

                  on(release){
                  _root.content_txt.variable = _root.news;
                  }

                  But what did this output:
                  on(release){
                  trace(_root.news);
                  trace(content_txt);
                  }

                  ?
                  • 6. Re: Change dynamic text var with onRelease
                    jondro Level 1
                    but 1 and but 2 are button symbols and

                    "on(release){
                    content_txt.variable = _root.news;
                    }"

                    just clears all the text

                    For

                    on(release){
                    trace(_root.news);
                    trace(content_txt);
                    }

                    the output was:

                    <b>News</b><br />Paintball Signups NOW! Contact any student council member or the student council board located between the automotive lab and the diesel lab to sign up.<br /><br />April 10, 2006 Student council BBQ (9AM-10PM)<br />July 22, 2006 "Thump Thunder and Shine" at DADC

                    undefined

                    This is driving me crazy
                    • 7. Re: Change dynamic text var with onRelease
                      jondro Level 1
                      *Correction*

                      Sorry the output was:

                      <b>News</b><br />Paintball Signups NOW! Contact any student council member or the student council board located between the automotive lab and the diesel lab to sign up.<br /><br />April 10, 2006 Student council BBQ (9AM-10PM)<br />July 22, 2006 "Thump Thunder and Shine" at DADC

                      _level0.content_txt
                      • 8. Re: Change dynamic text var with onRelease
                        jondro Level 1
                        Ok...so I am half way there and there is only one problem that I have left. I can get the variable to change from "news" to "carshow" when you click button 2 with the following actionsript:

                        on(release){
                        set("news", carshow);
                        }

                        However when I try inserting similar actionscript for but 1 to return it to its original value using this code:

                        on(release){
                        set("carshow", news);
                        }

                        The news text does not return. Why isnt this method working?
                        • 9. Re: Change dynamic text var with onRelease
                          jondro Level 1
                          Please help I cant get this to work...or any different ideas to get similar results??
                          • 10. Re: Change dynamic text var with onRelease
                            abeall Level 3
                            I'm not sure why you are using set(), it should work to just use:
                            on(release){
                            _root.content_txt.htmlText = _root.news;
                            }