7 Replies Latest reply on Sep 7, 2007 2:01 PM by jl2000

    One text field different content...

    jl2000 Level 1
      Hi -
      I have a single text field (dollar_t) that must show a different dollar amount for each button on the stage. No problem - I just wrote a bunch of "onRelease" functions - one for each of the 10 buttons - with the correct amount "hardcoded" in and it looked good. But then the customer requested that he be able to change the dollar amounts with a plain text editor. I know I can bring them in with load_vars but I'd have to make 10 files and 10 load_vars statements (one for each button)

      Is there a way I can put all 10 of the dollar amounts on one text file and then when the user clicks a button, the appropriate amount from the text file shows up in the text area "dollar_t" ?

      I've followed some threads here but none that I could fully understand and/or adapt to my purposes.

      TIA your input.
      jl
        • 1. Re: One text field different content...
          Level 7
          step one:
          in your external text file, enter this text:
          &a_txt=10&b_txt=18&c_txt=29...&j_txt=58
          (meaning - enter 10 different values, according to your customer's request)

          step two:
          give each of your buttons instance names 'a' through 'j'

          step three:
          once your txt file is loaded (using load_vars) you have in your movie 10
          variables, named 'a_txt' through 'j_txt', each with the appropriate value.

          step four:
          this might be a little complicated - hope you can follow. in a single loop
          operation, add the 'onRelease' handler for every buttom, and using some
          dymamic coding have the correct value is 'attached' to every button.
          something like that:

          var str:String = "a";
          for (var i=0;i<10;i++){
          _level0[str].onRelease = function(){
          dollar_t.text = this._name+"_txt";// the value of 'dollar_t' updates
          according to the value of variable which names correspond to the name of the
          clicked button
          }
          var nextChar = str.charCodeAt(0)+1; // turn the letter to number, and
          add 1 to it
          str = String.fromCharCode(nextChar); // turn the numeric value back to
          string
          }

          i've made it a bit complicated, but i hope thing are clear for you now.
          remember - always think dymically!

          good luck,
          eRez
          www.allofme.com


          "jlucchesi" <webforumsuser@macromedia.com> wrote in message
          news:fava18$m12$1@forums.macromedia.com...
          > Hi -
          > I have a single text field (dollar_t) that must show a different dollar
          > amount
          > for each button on the stage. No problem - I just wrote a bunch of
          > "onRelease"
          > functions - one for each of the 10 buttons - with the correct amount
          > "hardcoded" in and it looked good. But then the customer requested that
          > he be
          > able to change the dollar amounts with a plain text editor. I know I can
          > bring them in with load_vars but I'd have to make 10 files and 10
          > load_vars
          > statements (one for each button)
          >
          > Is there a way I can put all 10 of the dollar amounts on one text file and
          > then when the user clicks a button, the appropriate amount from the text
          > file
          > shows up in the text area "dollar_t" ?
          >
          > I've followed some threads here but none that I could fully understand
          > and/or
          > adapt to my purposes.
          >
          > TIA your input.
          > jl
          >

          • 2. One text field different content...
            jl2000 Level 1
            eRez - this looks like one of those threads I didn't understand ;-) but I'm going to try to work it out anyway with some help from you.

            The first thing I'll have to do is rename all the buttons because right now they have instance names like "mc1a, mc2, mc2a,mc3", etc - according to their position on the stage. But I'll change that.

            A question. On the text file is it OK that I include the dollar sign "$" before the number? Right now the text file starts like this: &a_txt=$8,450&b_txt=$9,700&c_txt=$16,000\

            Must it all be on one continuous line or can I start each & on a new one? It would help my customer if there was more white between the items.

            Thanks,
            JL

            P.P.S. I don't know what "think dynamically" means.
            • 3. Re: One text field different content...
              SymTsb Level 2
              you'll have to url encode the $ signs. I believe it is %24 or something like that. check this site to be certain - http://www.asciitable.com/
              • 4. Re: One text field different content...
                Level 7
                'think dynamically' means avoiding hard-coding, and using esily editable
                external data. it also means, not writing the same function 10 times for 10
                different buttons, but writing a loop which goes through all the buttons and
                attach a function to each. and so forth...

                about your code - you don't have to re-name your buttons, just make a little
                change to my previous code (which actually makes things more simpler, but
                involves an array):

                var btnsArr:Array = ["mc2","mc2a","mc3a","mc3b"...];// put into the array
                the names of all your buttons
                for (var i=0;i<btnsArray.length;i++){
                _level0[btnsArray ].onRelease = function(){
                dollar_t.text = "$"+this._name+"_txt";// the value of 'dollar_t'
                updates according to the value of variable which names correspond to the
                name of the clicked button
                }
                }

                using 'btnsArray.length' instead of 10, comes handy if the number of buttons
                changes in the future (that's also dynamic thinking...)
                as u see - i've also added the $ in the code, it doesn't have to be in your
                text file.

                good luck,
                eRez



                "jlucchesi" <webforumsuser@macromedia.com> wrote in message
                news:fb24nb$m0$1@forums.macromedia.com...
                > eRez - this looks like one of those threads I didn't understand ;-) but
                > I'm
                > going to try to work it out anyway with some help from you.
                >
                > The first question I have is about the instance names of the buttons.
                > I've
                > already been using names (like mc2, mc2a, mc3a, mc3b) to do other things
                > like
                > fading them out when it's not being used and things like that. It will
                > create
                > a lot of backtracking thru established code to get them all renamed to "a
                > thru
                > j " as you suggest. Will this still work if I leave the instance names as
                > they
                > are? Is it possible to work this if I match up the text file with the btn
                > names such as: &mc2_txt=$1000&mc2a_txt=$2200&mc3_txt=&1650....and so on?
                >
                > Thanks,
                > JL
                > P.S. The dollar sign has to be there. Is that a problem?
                > P.P.S. I don't know what "think dynamically" means.
                >

                • 5. Re: One text field different content...
                  jl2000 Level 1
                  eRez -
                  This isn't working. Please check what Ive done and see where I'm wrong.
                  Here's the way I put the text in "tool3.txt"....
                  &mc1a_txt=8,450&mc1b_txt=9,700&mc2a_txt=16,900 etc, etc.

                  I made a new text field on the stage for the $ amounts called tempdollar_t for testing purposes.

                  I don't know how to read each and every line so there could be an error anywhere. Can you see what's wrong?
                  Thanks for your help.
                  jl
                  • 6. Re: One text field different content...
                    jl2000 Level 1
                    eRez - Part of what's confusing the issue is that I first coded this page 6 months ago using the most primitive of statements - not at all dynamically. All together there are 15 btns - the first 5 trigger the 10 that we're playing with now. And each btn has on onRelease function with a LIST of things to do like change the alpha of all the other buttns except one or two, goto some frame. So it's all pretty messy...and it might be too far gone to start now being dynamic. Once the array of btns is established and the txt file is loaded via LoadVars, is there a way to add one line of code to each of the buttons to bring in its one PIECE of the txt file?
                    I know adding 10 lines of code is not the BEST way but considering the mess I've started with - it seems to be more logical than starting over.
                    Do you understand? Is it possible to get each button to bring in a specific item from a group of items on a text file?
                    That would be very helpful.
                    jl
                    • 7. Re: One text field different content...
                      jl2000 Level 1
                      I guess not then.