13 Replies Latest reply on Dec 13, 2010 9:48 AM by kglad

    send POST via flash

    iconofsin14 Level 1

      can someone give me an example of code which would be used to send a bunch of variables to a PHP script via flash
      This would require the PHP script to load when the data is sent.

      Incase it helps

      I want to use this for a Flash event calender which triggers more information about the event to appear in a HTML area of the page when an event is clicked on. The PHP file would be the same file that the SWF is embeded in so the FLASH file would reload the page with the variable sent to the PHP. The PHP would use this variable to select the right content from a MySQL database.

        • 1. Re: send POST via flash
          kglad Adobe Community Professional & MVP

          as2 or as3?


          • 2. Re: send POST via flash
            iconofsin14 Level 1

            better have both

             

            since i am using a freeware calandar (in the same way as one would use a freeware lightbox script) i dont know which version of AS i will end up using

            • 3. Re: send POST via flash
              kglad Adobe Community Professional & MVP

              as2, use loadvars and check the sendAndLoad() method.

               

              as3, use the urlloader class and check the urlvariables class.

              • 4. Re: send POST via flash
                iconofsin14 Level 1

                This may sound like a noobish question because it is

                are the things you have called classes  (urlloader and urlvariable in this case) like libraries of commands
                andthings such as stop(), goToframe(2) and addeventlistener specific commands which fall under one of the classes

                • 5. Re: send POST via flash
                  kglad Adobe Community Professional & MVP

                  in the flash help files, check the various classes for your actionscript version.

                  1 person found this helpful
                  • 6. Re: send POST via flash
                    iconofsin14 Level 1

                    I have been looking a a lot of as3 tutorials on this topic and cant seam to get my head arround it at all

                    it seams that it is very complex to just send data from flash using as3

                    is there is a simple way

                    or a way which will make sence to an AS3 noob

                    • 7. Re: send POST via flash
                      kglad Adobe Community Professional & MVP

                      here are the essentials in as3:

                       

                      var urlS:String="yourphp.php";
                      var urlR:URLRequest=new URLRequest(urlS);
                      var urlV:URLVariables = new URLVariables();
                      urlV.var1=whatever;
                      urlV.var2=whateverelse;
                      urlR.data=urlV;

                       

                      var urlLDR:URLLoader = new URLLoader()
                      urlLDR.addEventListener(Event.COMPLETE,dataSendAndLoadComplete);
                      urlLDR.load(urlR);

                       

                      function dataSendAndLoadComplete(e:Event){
                          var yourreturndata:* = e.target.data;  // cast this as appropriate data type
                      }

                      1 person found this helpful
                      • 8. Re: send POST via flash
                        iconofsin14 Level 1

                        i have found tutorials which look a lot like that but that code does not make any sense to me

                         

                        the as2 equivilant which looks something like GETURL("http://www.me.com",_POST) is easy to understand because GETURL is the command, everything in the brackets is its parameters in this case the place the data is going and the method of sending.

                         

                        What does each line of that do

                        which line determines if or not the page the data is going to loads or not?
                        which line determines where the data is sent to
                        which line detemines the send type (post, get ect)
                        does it send all variables which exist in the as3 script or does that need to be set?

                        also that uses "var" a lot thats how you set a variable so how can thoes be commands?

                        • 9. Re: send POST via flash
                          kglad Adobe Community Professional & MVP

                          kglad wrote:

                           

                          here are the essentials in as3:

                           

                          var urlS:String="yourphp.php"; // address of php script
                          var urlR:URLRequest=new URLRequest(urlS);  // info to be passed to the script

                          urlR.method = URLRequestMethod.POST;  // use "POST" method

                          var urlV:URLVariables = new URLVariables();  // urlvariable instance to be sent to the script
                          urlV.var1=whatever;  // var1 property or urlvariable.  ie, sending var1
                          urlV.var2=whateverelse;  // sending var2
                          urlR.data=urlV;  // assigns the data property of the urlrequest to your urlvariables instance

                           

                          var urlLDR:URLLoader = new URLLoader()  // creates a loader to send and load the urlrequest
                          urlLDR.addEventListener(Event.COMPLETE,dataSendAndLoadComplete);  // listens for return from the script
                          urlLDR.load(urlR);  // sends and loads urlR

                           

                          function dataSendAndLoadComplete(e:Event){
                              var yourreturndata:* = e.target.data;  // cast this return from the script as appropriate data type
                          }

                          1 person found this helpful
                          • 10. Re: send POST via flash
                            iconofsin14 Level 1

                            If I simply create a load of input text boxes and a button for submitting, put them on a movie clip or the stage
                            and copy/pasted  that code and changed the destination adress into an event handler which responds to a click of the button would it work?

                             

                            If yes.....
                            Would the text box instance names become the variable names in the PHP file?
                            Would it matter how many text boxes i had
                            How would i go about having 2 seperate forms in 1 swf (how would i stop one form submitting values from all fields)

                             

                            if no.....
                            what more would i need to do
                            i do know how to set a variable based on the text of a text box so dont worry about telling me how to do that, just tell me if i need to do that.

                            • 11. Re: send POST via flash
                              kglad Adobe Community Professional & MVP

                              iconofsin14 wrote:

                               

                              If I simply create a load of input text boxes and a button for submitting, put them on a movie clip or the stage
                              and copy/pasted  that code and changed the destination adress into an event handler which responds to a click of the button would it work?

                              no

                               

                              If yes.....
                              Would the text box instance names become the variable names in the PHP file?

                              no
                              Would it matter how many text boxes i had

                              no
                              How would i go about having 2 seperate forms in 1 swf (how would i stop one form submitting values from all fields)

                              you apply the variables you want to send using the urlvariables instance.

                               

                              if no.....
                              what more would i need to do
                              i do know how to set a variable based on the text of a text box so dont worry about telling me how to do that, just tell me if i need to do that.

                              that's what you need to do.

                               

                               

                              var urlS:String="yourphp.php"; // address of php script
                              var urlR:URLRequest=new URLRequest(urlS);  // info to be passed to the script

                              urlR.method = URLRequestMethod.POST;  // use "POST" method

                              var urlV:URLVariables = new URLVariables();  // urlvariable instance to be sent to the script
                              urlV.var1=whatever_textfield.text
                              urlV.var2=whateverelse_textfield.text

                              urlR.data=urlV;  // assigns the data property of the urlrequest to your urlvariables instance

                               

                              var urlLDR:URLLoader = new URLLoader()  // creates a loader to send and load the urlrequest
                              urlLDR.addEventListener(Event.COMPLETE,dataSendAndLoadComplete);  // listens for return from the script
                              urlLDR.load(urlR);  // sends and loads urlR

                               

                              function dataSendAndLoadComplete(e:Event){
                                  var yourreturndata:* = e.target.data;  // cast this return from the script as appropriate data type
                              }

                              1 person found this helpful
                              • 12. Re: send POST via flash
                                iconofsin14 Level 1

                                urlV.var1=whatever_textfield.text
                                urlV.var2=whateverelse_textfield.text

                                 

                                would i replace var1 and var2 with the names i wanted the variables to have in PHP

                                so for example if i wanted the content of textbox_one to be recived in php as $_POST['textone'] would i replace "urlV.var1" with "urlV.textone"

                                • 13. Re: send POST via flash
                                  kglad Adobe Community Professional & MVP

                                  exactly.