7 Replies Latest reply on Jul 1, 2011 7:08 AM by kglad

    Help required with multiple buttons

    rohanlon

      Hi all, i'm working on a charity project that entails the clicking of buttons in order to purchase a "virtual plot" on a grid system.

      There are hundreds of buttons involved.

       

      What I need to know are the following :

       

      a) Is there a way for me to set the actionscripting to a "parent" button then multi copy the button around the grid maintaining the scripting.

       

      b) When a button is clicked, it goes out to paypal, is there a way to AUTOMATICALLY disable the button once the transaction takes place

          and the user gets re-directed back to the website.

       

      c) When different buttons are clicked, is there a way to only have the URL of the last clicked button open up......in other words not have a whole

          load of different pages to the same paypal account open. (EG. If I click 20 buttons, I don't want 20 links to paypal open, only the last clicked button)

       

      I guess there is quite a bit of information I'm looking for help with but I am fairly new to Actionscript. Any help at all is greatly appreciated.

       

      Many thanks in advance.

      Ray

        • 1. Re: Help required with multiple buttons
          kglad Adobe Community Professional & MVP

           

          a) Is there a way for me to set the actionscripting to a "parent" button then multi copy the button around the grid maintaining the scripting.

          yes, but that's probably not what you want because each button will do exactly the same thing (unless you encode an if-statement that takes different actions based on the objects instance name).  you'll probably want to use a for-loop to encode your buttons so you don't have much typing to do.

           

          b) When a button is clicked, it goes out to paypal, is there a way to AUTOMATICALLY disable the button once the transaction takes place

              and the user gets re-directed back to the website.

          yes, as long as you setup flash and paypal to communicate when a transaction is completed.

           

          c) When different buttons are clicked, is there a way to only have the URL of the last clicked button open up......in other words not have a whole

              load of different pages to the same paypal account open. (EG. If I click 20 buttons, I don't want 20 links to paypal open, only the last clicked button)

          yes, but flash needs some way to determine a user has made the final choice.
          1 person found this helpful
          • 2. Re: Help required with multiple buttons
            rohanlon Level 1

            Actually in reply to point a) what I need is for each button to perform exactly

            the same task. The idea is that a purchaser buys a "virtual plot" of land on a grid.

            Each plot has it's own button so the action on each button is identical.

             

            Many thanks for the reply but as I stated earlier, I'm limited with my actionscript experience.

            I was wondering if anyone had code that does similar tasks or if they could possibly direct me

            towards fairly good tutorials. I've tried everywhere, and I'm an online subscriber to Lynda.com.

             

            Any help whatsoever would be fantastic.

            • 3. Re: Help required with multiple buttons
              kglad Adobe Community Professional & MVP

              ok, that means you'll have no way to differentiate which button was clicked and which plot was purchased.

               

              as2 or as3?  and what code do you want each button to execute?

              1 person found this helpful
              • 4. Re: Help required with multiple buttons
                rohanlon Level 1

                Every button (850 of them approx) has a different instance name.

                In actionscript 3, I then assign the paypal url to each different instance name.

                I'm about 30% there and as you can imagine, it's a fairly onerous task, not to

                mention the amount of lines of code in my AS3 file. The code that's being

                executed is to navigate to paypal on the mouseclick. The idea is that you

                click a button, navigate to PPal and make a donation.

                 

                There must be a way for me to do this in a much easier way ?

                 

                Is there a way for me to assign the URL to the instances globally

                rather than having to copy/paste and edit each one individually ?

                 

                By the way, I really appreciate your input, many thanks.

                • 5. Re: Help required with multiple buttons
                  kglad Adobe Community Professional & MVP

                  if you've chosen the instance names wisely (eg, btn1, btn2, ..., btn850), you can encode them all using:

                   

                   

                  for(var i:int=1;i<=850;i++){

                  this["btn"+i].addEventListener(MouseEvent.CLICK,f);

                  }

                   

                  function f(e:Event):void{

                  //whatever

                  }

                   

                  //  if you've chosen those names unwisely so there's no pattern, you can use use an array and leveage a for-loop to minimize typing.

                  • 6. Re: Help required with multiple buttons
                    rohanlon Level 1

                    Hi Kglad,

                     

                    I will try that when I get home.

                     

                    I do have the instances in a uniform convention (b001 - b850) so it looks like

                    your suggestion may work. Can't wait to try it.

                     

                    I know I'm being cheeky here but if you had a little bit of similar code that I can

                    add on the end to lock out or disable the button, I would be seriously indebted

                    to you.

                     

                    Also is it possible that when I disable the button (after it has gone through

                    the paypal process), I can show a graphic of a big red X or similar to signify

                    that particular button is now disabled.......

                     

                    YOU HAVE NO IDEA HOW MUCH OF A HELP YOU ARE.

                     

                    R

                    • 7. Re: Help required with multiple buttons
                      kglad Adobe Community Professional & MVP

                      you can disable a button by using its enabled or mouseEnabled property.  also, to indicate a button is disabling it's customary to use its alpha property:

                       

                      for(var i:int=1;i<=850;i++){

                      this["b"+formatF(i)].addEventListener(MouseEvent.CLICK,f);

                      }

                       

                      function f(e:Event):void{

                      e.currentTarget.alpha=.3;

                      e.currentTarget.enabled=false;

                      //whatever

                      }

                       

                      function formatF(i:int):String{

                      var s:String=String(i);

                      while(s.length<3){

                      s="0"+s;

                      }

                      return s;

                      }