9 Replies Latest reply on Jun 6, 2012 8:01 AM by kglad

    Passing variables from AS2.0 to PHP

    Hendrik576

      Hello!

       

       

      I'm having problems with the upload section of my website.

      People can enter the details of a song and upload it.

      When it is uploading, a file called appenlist will send the variables to my xmlplaylist.

      But when i check my playlist afterwards, the variables are empty.

       

       

      This is my AS2 code

       

       

       

      lvSend = new LoadVars();

      lvSend.titel = tTitel.text;

      lvSend.artist = tArtist.text;

      lvSend.genre = tGenre.getValue();

      lvSend.name = file.name;

      lvSend.sendAndLoad("appendlist.php", lvReceive, "POST");

       

       

      The instance names of my input text fields are tTitel, tArtist and tGenre

       

      The added text in my xml playlist looks like this:

       

       

      <listitem name='' - ''>

      <stream name=''>

      </listitem>

       

       

       

      Instead of the variables it gives nothing just '' instead of 'variable1'.

       

       

      My code for receiving the variables in php is this:

       

       

       

      $titel = $_POST['titel'];

      $artist = $_POST['artist'];

      $genre = $_POST['genre'];

      $name = $_POST['name'];

       

       

       

      Why are my variables empty? Did something went wrong while passing the variables?

       

       

      I'm using WampServer to host my site locally.

       

       

      Any help is appreciated!

      Hendrik-Jan

        • 1. Re: Passing variables from AS2.0 to PHP
          kglad Adobe Community Professional & MVP

          lvSend properties must be defined AFTER your textifields' text properties are changed by your user.

          1 person found this helpful
          • 2. Re: Passing variables from AS2.0 to PHP
            Hendrik576 Level 1

            Hi kglad!

             

            Thanks for your answer

            But i have to admit that i don't know what you mean.

            Could you clarify it a little bit more? Maybe with an example?

             

            Thx!

            • 3. Re: Passing variables from AS2.0 to PHP
              kglad Adobe Community Professional & MVP

              what triggers the code you showed to execute?

              • 4. Re: Passing variables from AS2.0 to PHP
                Hendrik576 Level 1

                This is my code

                 

                 

                 

                import flash.net.FileReference;

                 

                 

                _root.info = "Select a FLV-file to upload it.";

                 

                 

                var bestandTypes:Array = new Array();

                 

                 

                var imageTypes:Object = new Object();

                imageTypes.description = "Video's (*.flv)";

                imageTypes.extension = "*.flv;";

                bestandTypes.push(imageTypes);

                 

                 

                //class aanspreken

                var fileRef:FileReference = new FileReference();

                 

                 

                //de blader knop

                selecteerBestand.onRelease = function() {

                          fileRef.browse(bestandTypes);

                };

                 

                 

                //upload knop en upload progres balk onzichtbaar maken

                uploadKnop._visible = false;

                progresBalk.balk._visible = false;

                progresBalk.balk._xscale = 0;

                 

                 

                //een listener aanmaken waarmee we allerlei gegevens kunnen opvragen

                var listener:Object = new Object();

                 

                 

                listener.onSelect = function(file:FileReference) {

                          //bestand is te groot

                          if (file.size>104857600) {

                 

                                    _root.info = "Max size is 10 MB!";

                          } else if (file.type.toLowerCase() != ".flv") {

                                    _root.info = "Only FLV types are allowed!";

                          } else {

                                    uploadKnop._visible = true;

                                    _root.info = "Name: "+file.name+"\n";

                                    _root.info += "Size: "+Math.round((file.size)/1024)+" kb"+"\n";

                                    _root.info += "Extension: "+file.type+"\n";

                                              _root.info += "\n";

                                    _root.info += "Press the upload button!";

                 

                 

                                    uploadKnop.onRelease = function() {

                                              //het gaat fout

                                              if (!file.upload("upload.php")) {

                                                        _root.info = "Kan niet uploaden!";

                 

                 

                                              }

                                              //het gaat goed dus...

                                              else {

                                                        progresBalk.balk._visible = true;

                 

                 

                 

                                              }

                 

                                    };

                          }

                          

                };

                 

                 

                //uploaden is bezig

                listener.onProgress = function(file:FileReference, bytesLoaded, bytesTotal){

                          //procenten tonen hoeveel er al is ge upload

                          _root.info = "Gedaan "+Math.round(bytesLoaded/bytesTotal*100)+"% van "+file.size;

                          //balk in laadBalk laten groeien

                          progresBalk.balk._xscale = bytesLoaded/bytesTotal*100;

                };

                 

                 

                //klaar met uploaden

                listener.onComplete = function(file:FileReference){

                 

                                    lvSend = new LoadVars();

                                    lvSend.titel = tTitel.text;

                                    lvSend.artiest = tArtist.text;

                                    lvSend.genre = tGenre.getValue();

                                    lvSend.naam = file.name;

                                    lvSend.sendAndLoad("appendlist.php", lvReceive, "POST");

                 

                          _root.info = file.name+" is uploaded!";

                 

                          progresBalk.balk._visible = false;

                          uploadKnop._visible = false;

                }

                 

                 

                //listener aan de ref hangen

                fileRef.addListener(listener);

                • 5. Re: Passing variables from AS2.0 to PHP
                  kglad Adobe Community Professional & MVP

                  you may be out of scope in that listener function and lvReceive is undefined.  use the trace() function to check scope and define lvReceive.  and you may as well fix lvSend, too

                   

                  var lvSend:LoadVars=new LoadVars();

                  lvReceive:LoadVars=new LoadVars();

                   

                  listener.onComplete = function(file:FileReference){

                    trace(this);

                  trace(tTitel);

                  trace(tTitel.text);

                                      lvSend.titel = tTitel.text;

                                      lvSend.artiest = tArtist.text;

                                      lvSend.genre = tGenre.getValue();

                                      lvSend.naam = file.name;

                                      lvSend.sendAndLoad("appendlist.php", lvReceive, "POST");

                   

                            _root.info = file.name+" is uploaded!";

                   

                            progresBalk.balk._visible = false;

                            uploadKnop._visible = false;

                  }

                  1 person found this helpful
                  • 6. Re: Passing variables from AS2.0 to PHP
                    Hendrik576 Level 1

                    Hi kglad!

                     

                    I did all of the above and my output is

                     

                    _level0.pages.content.uploadKnop

                    _level0.pages.content.tTitel

                    testingtitel

                     

                    So the variables in flash work. i will paste the code of my appendlist.php, maybe that helps

                     

                    <?php

                    $titel = $_POST['titel'];

                    $artist = $_POST['artist'];

                    $genre = $_POST['genre'];

                    $name = $_POST['name'];

                     

                     

                    $data = file('newlist.xml'); // reads an array of lines

                    function replace_a_line($data) {

                       if (stristr($data, nextlistitem')) {

                                        return           "<listitem name='$artist' - '$titel'>

                                        <stream name='$name' start='0' len='-1'/>

                              </listitem>";

                       }

                       return $data;

                    }

                    $data = array_map('replace_a_line',$data);

                    file_put_contents('newlist.xml', implode('', $data));

                     

                     

                    ?>

                     

                    So my php file checks each line of code in my xmllist and when it finds the line 'nextlistitem' it will add the new song at that line.

                    Did i make an error in this file?

                    • 7. Re: Passing variables from AS2.0 to PHP
                      kglad Adobe Community Professional & MVP

                      you have, at least, one php typo:

                       

                        if (stristr($data, nextlistitem')) {

                       

                      should be

                       

                        if (stristr($data, 'nextlistitem')) {

                      • 8. Re: Passing variables from AS2.0 to PHP
                        Hendrik576 Level 1

                        that doesn't seem to the problem. I fixed it, but still nothing...

                         

                        any suggestions?

                        • 9. Re: Passing variables from AS2.0 to PHP
                          kglad Adobe Community Professional & MVP

                          use the echo function to debug your php.

                          1 person found this helpful