16 Replies Latest reply on Jan 12, 2011 8:02 AM by Tony404

    Php, xml and Flash

    Tony404 Level 1

      Hi

       

      Can any one help me. I am trying to query a  sql database and echo the image into xml so I can view the queried image in flash.

       

      I already know how to query and echo the image url from the database.

       

      This is the code:

       

      //The database is already queried at this point.

       

      echo "<?xml version=\"1.01\"?>\n";

       

      echo "<content>\n";

       

      while($nile=mysql_fetch_assoc(run))

      {

       

      echo "<item>".$nile['content']."</item>\n";

       

      }

       

      echo "</content>\n";

       

       

       

      //In flash I creat an xml object and a urls array to insert echoed images. It looks like this.

       

       

      //This is after creating the xml object and url array in side the for loop to insert the xml.

       

       

      thexml.onLoad=function()

      {

       

      var photos:Array=thisfirstChild.childNodes;

       

      for(i=0;i<photos.length;i++)

      {

      //this pushs the xml data into a urls array

       

      urls.push(photos[i].attributes.url);

       

      }

      //This is supposed to load individual data in the to movie object in flash.

       

      movieobject.loadMovie(urls[0]);

      movieobject.loadMovie(urls[1]);

      }

       

      x.load(content.php);

       

       

       

       

      The echoed xml in the first code produces a url link that contains a link to an image in the database. The flash is supposed to display the image on a flash movie clip call movieobject. I am having problem getting the image displayed in flash. If any one can modify or provide new code it would be really helpfull.

        • 1. Re: Php, xml and Flash
          Tony404 Level 1

          Hi

           

          Just wondering if any one has seen my posting and willing to help?

          • 2. Re: Php, xml and Flash
            David_Powers Adobe Community Professional (Moderator)

            Tony404 wrote:

             

            Just wondering if any one has seen my posting and willing to help?

            It would help if you posted in the correct forum to start with. I have moved your post from the Dreamweaver forum to the Flash ActionScript 1 and 2 forum, which seems more appropriate.

             

            Others can help you with the ActionScript side of things, but just looking at your PHP, the following line is incorrect:

             

            while($nile=mysql_fetch_assoc(run))
            

             

            The argument passed to mysql_fetch_assoc() needs to be a database resource, which would begin with a dollar sign.

            • 3. Re: Php, xml and Flash
              Tony404 Level 1

              Hi

               

              Thanks for the reply and correcting my post. The php problem you specified was fixed. Its pretty hard to copy and paste code directly into the forum so I had to re write all the code by hand.

              • 4. Re: Php, xml and Flash
                kglad Adobe Community Professional & MVP

                so, is your problem resolved?

                • 5. Re: Php, xml and Flash
                  Tony404 Level 1

                  No its not solved.

                   

                   

                  I still cant read the echoed php/xml in action script.

                  • 6. Re: Php, xml and Flash
                    kglad Adobe Community Professional & MVP

                    you have, at least, one error in your loadvars code (thexml and x are not the same) and may have many more.

                     

                    show all the code as2 code related to created and using your loadvars instance(s).

                    • 7. Re: Php, xml and Flash
                      Tony404 Level 1

                      Hi Thanks for the reply.

                       

                      The x works correctly. It just that I had to type all the code by hand for the forum. I could`nt copy and paste.

                       

                       

                      My action script works well when getting an image from a folder on my desktop with the published flash in the same folder.

                       

                      using this code:

                       

                      <images>

                      <clip1 url="mini.png"/>

                      </images>

                       

                      The action script is just the same.

                       

                      A problem appears when I try and get the image url from my sql database instead of a file on my desktop.

                       


                      I dont know how to read my echoed xml correctly in action scipt. If any one has done it before please upload code.

                       

                       

                      A image url is contained in my database. The Php echoes the image url and turns it into xml to be read by actionscript. I believe that my  echoed xml is insuffiecent . I dont know how to correctly read it in flash i.e the attributes.

                      • 8. Re: Php, xml and Flash
                        kglad Adobe Community Professional & MVP

                        use ctrl-c to copy and ctrl-v to paste.

                         

                        for your xml, use the following after defining staryourappF():

                         

                        var urls:Array = [];
                        var xml:XML = new XML();
                        xml.ignoreWhite = true;
                        xml.onLoad = parseXML;
                        xml.load("content.php");

                        function parseXML(){
                            for(var i:Number=0;i<this.firstChild.childNodes.length;i++){
                                urls.push(this.firstChild.childNodes[i].firstChild.nodeValue);
                            }
                            startyourappF();
                        }

                        • 9. Re: Php, xml and Flash
                          Tony404 Level 1

                          Thanks for the crtl v:

                           

                          This is my php code. That echoes the xml url from my table that reffers to an image.png in my server.

                           

                           

                          <?Php
                           
                          header("Content-Type:text/xml");
                          //set the content type to xml
                          // Initialize the xmlOutput variable
                          $xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';

                           

                          $xmlBody .= "<XML>";

                           

                          include ("connect.php");

                           

                          $id=$_SESSION['id'];

                           

                           

                          $Ads=mysql_query("SELECT * FROM data WHERE id='$id'");

                           

                          while($nile=mysql_fetch_assoc($Ads))
                          {
                              $ads = $nile['adcontent'];

                          //echoed xml reffering to a image url contained in the database.


                              $xmlBody .= '
                          <Data>
                              <DataURL='.$ads.'/>
                          </Data>';
                             
                             
                          }

                           

                          // This is my original actionscript to read the echoed xml url and to display images echoed.

                           

                          /*code to program xml code*/

                           

                          var thexml:XML =new XML();
                          thexml.ignoreWhite=true;

                           

                          var urls:Array=new Array();
                          thexml.onLoad=function()
                          {
                             
                              var photos:Array=this.firstChild.childNodes;
                              for(i=0;i<photos.length;i++)
                              {
                                 
                                  urls.push(photos[i].attributes.URL);
                              }

                           

                          holder.loadMovie(urls[0]);   
                          }       
                          thexml.load("profile.php");

                           

                          // From your uploaded code I do not understand startyourappF(); would this be the holder.loadMovie(urls[0]) part. Should I type it as it is or is it a comment. From my uploaded original code I hope you could guide me to displaying the images from the collected database table cheers.

                           

                           

                          //This what the xml in profile.php displays when viewed in page source.

                           

                          <?xml version="1.0" encoding="ISO-8859-1"?><XML>
                          <Data>
                              <DataURL=Adverts/viola_004.png/>
                          </Data></XML>   

                           

                          The image i want to access is the Adverts/viola_004.png to be display on a flash movie clip.

                          • 10. Re: Php, xml and Flash
                            kglad Adobe Community Professional & MVP

                            use:

                             


                             

                            var urls:Array = [];

                            var index:Number;

                            var xml:XML = new XML();
                            xml.ignoreWhite = true;
                            xml.onLoad = parseXML;
                            xml.load("content.php");

                            function parseXML(){
                                for(var i:Number=0;i<this.firstChild.childNodes.length;i++){
                                    urls.push(this.firstChild.childNodes[i].firstChild.nodeValue);
                                }

                            index = 0;

                             

                                startyourappF();
                            }

                             

                            function startyourappF(){

                            holder.loadMovie(urls[index]); 

                            }

                            • 11. Re: Php, xml and Flash
                              Tony404 Level 1

                              Thank you so much for the upload.

                               

                              I have been looking for help to solve this problem for months.

                               

                              Can I ask. How can I modify the size of read elements in flash.

                               

                               

                              So lets say I: holder.LoadMovie(index[urls]);

                               

                               

                              And I want the loaded movie to be a specific size. How could I do this.

                               

                               

                              I promise this is my last question.

                              • 12. Re: Php, xml and Flash
                                kglad Adobe Community Professional & MVP

                                you'll need to use preloader code to determine when loading is complete because only after loading is complete can you assign the width/height of the target movieclip:

                                 

                                var urls:Array = [];

                                var index:Number;

                                var xml:XML = new XML();
                                xml.ignoreWhite = true;
                                xml.onLoad = parseXML;
                                xml.load("content.php");

                                function parseXML(){
                                    for(var i:Number=0;i<this.firstChild.childNodes.length;i++){
                                        urls.push(this.firstChild.childNodes[i].firstChild.nodeValue);
                                    }

                                index = 0;

                                 

                                    startyourappF();
                                }

                                 

                                function startyourappF(){

                                this.onEnterFrame = preloadF;

                                holder.loadMovie(urls[index]); 

                                }


                                function preloadF(){

                                if(holder.getBytesLoaded()>50&&holder.getBytesLoaded()>=holder.getBytesTotal()){

                                delete this.onEnterFrame;

                                holder._width = whatever;

                                holder._height = whateverelse;

                                }

                                }

                                 

                                p.s.  please mark this thread as answered, if you can.

                                1 person found this helpful
                                • 13. Re: Php, xml and Flash
                                  Tony404 Level 1

                                  Hi it me again thank for the help. The code worked well.

                                   

                                  I promise this is the last time question regarding this discussion.

                                   

                                  After recieving your code I tried to manipulate it so that I could load more that one image from the array on different movie clip objects the code looks

                                  like this:

                                   

                                  var urls:Array = [];

                                   

                                  var index:Number;
                                  var index1:Number;

                                   

                                   

                                   

                                  var xml:XML = new XML();
                                  xml.ignoreWhite = true;
                                  xml.onLoad = parseXML;
                                  xml.load("content.php");

                                   

                                  function parseXML(){
                                      for(var i:Number=0;i<this.firstChild.childNodes.length;i++){
                                          urls.push(this.firstChild.childNodes[i].firstChild.nodeValue);
                                      }

                                   

                                  index=0;
                                  index1=1;

                                   

                                   

                                   

                                      startyourappF();

                                   

                                  }

                                   

                                   

                                   

                                  function startyourappF(){

                                   

                                  this.onEnterFrame = preloadA;

                                   

                                  holder.loadMovie(urls[index]);

                                   

                                  holder1.loadMovie(urls[index1]);
                                  }

                                   

                                  function preloadA(){

                                   

                                  if(holder.getBytesLoaded()>50&&holder.getBytesLoaded()>=holder.getBytesTotal()){

                                   

                                  delete this.onEnterFrame;

                                   

                                  holder._width = 260.0;

                                   

                                  holder._height = 96.0;
                                  }
                                  if(holder1.getBytesLoaded()>50&&holder1.getBytesLoaded()>=holder1.getBytesTotal()){

                                   

                                  delete this.onEnterFrame;

                                   

                                  holder1._width = 260.0;

                                   

                                  holder1._height = 96.0;
                                  }
                                  }

                                   

                                   

                                  The code sucessfully loads the first image to holder but is unable to load the second url to holder1 and others I want to add. I spend the whole night trying out different configurations of the code but with no success.

                                   

                                  I hope you can help me. All I need is more than one image loaded from the urls array variable into multiple other holder variables.

                                  Hope you can help.

                                   

                                  cheers>>

                                  • 14. Re: Php, xml and Flash
                                    Tony404 Level 1

                                    Hi Just wondering if you got my reply.

                                     

                                    Sorry for the bother. I promise this is that last.

                                     

                                    I just need to know how I can replicate the displaying process on multiple movie holders.

                                    • 15. Re: Php, xml and Flash
                                      annyphp

                                      More PHP XML you can view

                                      • 16. Re: Php, xml and Flash
                                        Tony404 Level 1

                                        Hi

                                         

                                        You probable do not remember me. You helped me out reading xml into flash some time ago.

                                         

                                        At the moment I have been trying to do a smilar task that involves reading xml audio or video files the same way. The difference is that this is audio/video and I need the loaded video/audio to play one after another and when the last video or audio finishs I would like to direct the code to another function.

                                         

                                         

                                        Only five audio/video are loaded from xml, they then are loaded to a movie clip object and play until the last one plays after this a new function runs.

                                         

                                        I hope you understand my dilema and hope you can help.

                                         

                                         

                                        Thank you.