0 Replies Latest reply on Apr 13, 2009 12:53 PM by TheScarecrow

    XML & Actionscript parsing

    TheScarecrow Level 1

      OK I have this working so far.  I have a couple of questions that I hope someone can answer.  I have this ActionScript that reads the XML file into the flash movie.  The poblem is this:  The XML is in this format:

       

      <listitem name="TEST" url="rtmp://000.000.000.000/">
            <stream len="-1" name="Test" start="0"/>
            <group name="Testing"/>
      </listitem>

      <menu>
            <listitem name="Test"/>

      </menu>

      <group>

           <listitem name="Testing">

      </group>

       

      I can get the actionscript to read in the listitem name and the thumbnail of the video.  I want to make a list of the unique group names as well and send to flash to put into a list component.  however I am having trouble getting the actionscript to do it.  Can anyone help me? I am really struggling with this. Thanks.

       

      See actionscript below:

       

      import mx.video.*;
      //Set up the list box, call function VideoThumb to create the actual thumbnails
      list.rowHeight = 70;
      list.cellRenderer = "VideoThumb";
      list.selectable = true;
      list.setStyle("color", 0xFFFFFF); //text Color
      list.setStyle("backgroundColor", 0xC8AA5C); //background color
      list.setStyle("borderStyle", "none"); //
      //Scrollbar qualities
      list.ScrollBar.setStyle("scrollTrackColor", 0x0000ff);
      list.UIScrollBar.setStyle("symbolColor", 0x0000ff);
      list.UIScrollBar.setStyle("borderStyle", "none");
      //rollover colors
      list.setStyle("rollOverColor", 0x2E1602);//rollover color
      list.setStyle("textRollOverColor", 0x2E1602);//text rollover color
      list.setStyle("selectionColor", 0x2E1602);
      list.setStyle("textSelectedColor", 0x000000);
      //Set up the list box, call function VideoThumb to create the actual thumbnails
      list2.rowHeight = 25;
      list2.cellRenderer = "CategoryList";
      list2.selectable = true;
      list2.setStyle("color", 0xFFFFFF); //text Color
      list2.setStyle("backgroundColor", 0xC8AA5C); //background color
      //create new empty listener object
      listListener = {};

       

      //nc = new NetConnection();             //create a connection
      //nc.connect( nav.attributes.url );     //connect to FCS
      //ns = new NetStream(nc);             //create a stream
      //ns.connect();                         //connect the stream

       

      nc.connect(null);
      var stream_ns:NetStream = new NetStream(nc);
      stream_ns.play("video2.flv");

       

      // Create function to trace all the status info.
      function traceStatus(info) {
           Message.text+="Level: " + info.level + " Code: " + info.code+"\n";
      }    // Assign this function to onStatus handlers when you create objects.

       


      //Function to handle what happens when an item in the list is selected
      listListener.change = function( evtobj ) {
           var nav = list.dataProvider[list.selectedIndex];
           var reset = true;
           attachMovie("FLVPlayback", "my_FLVPlybk", 10, {width:640, height:480, x:10, y:110});
           for ( var i = 0; i < nav.childNodes.length; i++ ) {
               var stream = nav.childNodes[i];
               if ( stream.nodeName == "stream" ) {
                  
                  
                   //center the FLVPlayback component when FLV is ready to play
                   var listenerObject:Object = new Object();
                   listenerObject.resize = function(eventObject:Object):Void {
                       //center video in playback area
                       //newx = (460 - my_FLVPlybk.preferredWidth)/2;
                       //newy = (470 - my_FLVPlybk.preferredHeight)/2;
                       //my_FLVPlybk._x = newx;
                       //my_FLVPlybk._y = newy;
                   };
                   my_FLVPlybk.addEventListener("resize", listenerObject);   
                   listenerObject.ready = function(eventObject:Object):Void {
                       my_FLVPlybk.setSize(500, 700);
                   };

       

                  my_FLVPlybk.skin = "ClearExternalAll.swf";
                   my_FLVPlybk.clear();
                   my_FLVPlybk.contentPath = nav.attributes.url + stream.attributes.name+".flv";
                   my_FLVPlybk.autoSize = true;
                   //trace(my_FLVPlybk.contentPath);
                   reset = false;
               }
           }
      }

       

       

       

      //Add an event listener on the list, when it triggers, run the listListener function to repopulate the list
      list.addEventListener("change", listListener);

       


      //Function that loads the XML file, parses it, and builds the list of available video clips
           var xmllist = new XML();          //setup a variable to hold the XML
           xmllist.ignoreWhite = true;
           xmllist.load( "videolistrss.xml" );     //load the XML file
           //The following gets called when the XML has been loaded
           xmllist.onLoad = function( status )  {
               if ( !status )
                   trace( status );
               var entries = this.childNodes[0];
               var playlists = {};
               var nav = [];
              
               for ( var i = 0; i < entries.childNodes.length; i++ ) {
                   var entry = entries.childNodes[i];
                   if ( entry.nodeName == "listitem" ) {
                       //builds array of video clip names
                       playlists[entry.attributes.name] = entry;
                       //trace(entry);
                   } else if ( entry.nodeName == "menu" ) {
                       //builds array of available videos
                       for ( var j = 0; j < entry.childNodes.length; j++ )
                       nav[j] = playlists[entry.childNodes[j].attributes.name];
                       //trace(entry);
                   }    //end else if
                  
               } //end if
               //sends the array of videos to the listbox UI
               list.dataProvider = nav;
              
               grouplists = [];
               for (var k = 0; k < entries.childNodes.length; k++) {
                   //trace(k);
                   var groups = entries.childNodes[k];
                   if ( entry.nodeName == "group" ) {
                       //builds array of video clip names
                       grouplists[entry.attributes.name] = entry;
                       //trace(groups);
                   }
               }
               groupNames.dataProvider = grouplists;
           } //end xmllist.onl