10 Replies Latest reply on Sep 6, 2010 9:35 AM by d_larry

    Array to dynamic box

    d_larry

      Hi there,

       

      I have 4 buttons, all have a number (1 - 4)

       

      I want these numbers to be entered into a dynamic box every time one of the buttons is clicked.

       

      The dynamic box should only have 4 characters in it, so when a button is clicked, the first characted is dropped, they all move along one and the new character (entered by pressing the button) is added to the end of the string of numbers.

       

      I assume this is done in an array somehow.

       

      Set an array of 4 elements.

      when the button is clicked, [0] = [1], [1] = [2]... etc.

       

      Then [3] = the number of the button.

       

      And then this array is assigned to the box.

       

      Does this seem like a good way to go about it. i have had a play around but cant seem to get the syntax right.

       

      Any help would be fantastic.

       

      Cheers

       

      Dave

        • 1. Re: Array to dynamic box
          Ned Murphy Adobe Community Professional & MVP

          You could just continuously build the string of values and only extract the last four from it each time the string changes.

          • 2. Re: Array to dynamic box
            d_larry Level 1

            that could work, not too sure how to extract the last for digits though.

             

            have you got a simple example?

             

            sorry, very new to all this. i have some understanding of the logic, just not that great at the code.

             

            Cheers!

             

            appreciate it

            • 3. Re: Array to dynamic box
              Ned Murphy Adobe Community Professional & MVP

              Look into the substr() method of the String class, and play with the aspect of specifying a negative start value.  The help docs have examples.

              1 person found this helpful
              • 4. Re: Array to dynamic box
                d_larry Level 1

                ok thanks!

                 

                ill have a look.

                 

                you think the other way wont work atall?

                 

                cheers

                • 5. Re: Array to dynamic box
                  d_larry Level 1

                  also,

                   

                  how would i add a character to the box, next to what ever is in there?

                   

                  eg.

                   

                  on (release){

                  box= "current values" + "14"

                  }

                  • 6. Re: Array to dynamic box
                    Ned Murphy Adobe Community Professional & MVP

                    What exactly is the box?

                    • 7. Re: Array to dynamic box
                      d_larry Level 1

                      it is a dynamic text box.

                       

                      i would like something to happen within the scene when the buttons are clicked in the correct order.

                       

                      to do this i thought if i create a dynamic box where the numbers are entered and when they are in the correct order, it will do a goTo function.

                       

                      i managed to do it simply with no maths, but it had its floors.

                       

                      so i was attempting to do it with an array.

                       

                      with an array for buttons, would i create a layer for actionscript, then make the array inside the 1st frame. and then call it from the actionscript within the button?

                       

                      so far i have

                       

                       

                      in action script layer frame...

                       

                      var combiNum = new Array();

                       

                      combiNum[0] = "1";

                      combiNum[1] = "2";

                      combiNum[2] = "3";

                      combiNum[3] = "4";

                       

                       

                      in button one actionscript...

                       

                       

                      on (release){

                       

                       

                           combiNum[0] = combiNum[1];

                           combiNum[1] = combiNum[2];

                           combiNum[2] = combiNum[3];

                           combiNum[3] = "1");

                       

                       

                           box = combiNum

                       

                       

                           if (box == 1423) {

                           gotoAndPlay(....);

                           }

                       

                      }

                       

                      i know the syntax isnt right, but is it in the right direction?

                       

                      cheers

                      • 8. Re: Array to dynamic box
                        Ned Murphy Adobe Community Professional & MVP

                        You can manipulate an array to have it push() an item on the end and splice() the one off the front, but I think using a string will be less work.  If you prefer to use an array approach, then look up those two methods.  In either case, without knowing what the box involves leaves it up to you to work with it.

                        1 person found this helpful
                        • 9. Re: Array to dynamic box
                          Ned Murphy Adobe Community Professional & MVP

                          Your best bet will be to pursue whatever approach you prefer and use the correct syntax.  You can probably solve this yourself, but you need to take the time to study what you have versus what you need.

                          • 10. Re: Array to dynamic box
                            d_larry Level 1

                            thanks again for your replies.

                             

                            i have managed to work it out, and it a lot easier than i thought.

                            i always seem to try it the hard way. ha

                             

                            cheer for your help.

                             

                            got one more question though...

                            i made the process into a function, for the button to call.

                             

                            at the moment it calls it from inside the button.

                             

                            on(release) {

                                   function("1");

                            }

                             

                            but is there a way to call if from the root(i think thats what its called) frame in the actionscript layer?

                             

                             

                            so in that one frame there are some variables, a function then something like this...

                             

                            mybutton.onRelease.function("1");

                             

                            i have tried this, and it doesnt seem to work.

                             

                            what are your thoughts?

                             

                            cheers

                             

                            dave