6 Replies Latest reply on Oct 21, 2011 1:11 PM by softkens01

    Loading the vidlist.xml file with ActionScript

    softkens01 Level 1

      Hi everyone,

      I'm following lessons 11 on ActionScript 3.0 (classroom in a book) and I am using Flash professional CS4; I have properly copied and pated lessons from the CD to my PC. I'm up to the stage where it describes the process of loading external files dynamically by using xml list. I have followed it to a tee, however when I came round to test it, it does load the list however the next video is not showing up. Please note that the first video is set from Component Inspector.

      Can anyone shed any light onto this?

      Thanks,

      softkens

        • 1. Re: Loading the vidlist.xml file with ActionScript
          kglad Adobe Community Professional & MVP

          copy and paste the code that plays the next video after the previous one completes play.

          • 2. Re: Loading the vidlist.xml file with ActionScript
            softkens01 Level 1

            Hello Kglad,

             

            Thank you for your answer. Here is the script for this task and videos are already in a folder within the same directory.

            Which code to paste?

             

            import fl.controls.ColorPicker;

            import fl.events.ColorPickerEvent;

            import fl.events.SliderEvent;

            import fl.video.FLVPlayback;

            import fl.video.VideoEvent;

             

            var vidList_XML:XML;

            var vidTitle:String;

            var count:int = 0;

            var xmlLoader:URLLoader = new URLLoader();

            xmlLoader.load(new URLRequest("vidlist.xml"));

            xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

             

            function xmlLoaded(event:Event):void {

                vidList_XML = new XML(xmlLoader.data);

                vidPlayer.addEventListener(VideoEvent.COMPLETE, changeVid);

                title_txt.text = "This is the first Video File";

            }

             

            function changeVid(e:VideoEvent):void {

                var nextVid:String = "../video/"+vidList_XML.vid[count].file;

                vidPlayer.source = nextVid;

                vidTitle = vidList_XML.vid[count].name;

                title_txt.text = vidTitle;

                vidPlayer.skinBackgroundColor = Math.random() * 0xFFFFFF;

                count++;

            }

             

            alphaSlide.addEventListener(SliderEvent.CHANGE, alphaChange);

             

            function alphaChange(e:SliderEvent):void {

                vidPlayer.skinBackgroundAlpha = e.target.value;

            }

             

            colorChoose.addEventListener(ColorPickerEvent.CHANGE, changeHandler);

             

            function changeHandler(e:ColorPickerEvent):void {

                var cp:ColorPicker = e.currentTarget as ColorPicker;

                vidPlayer.skinBackgroundColor = Number("0x" + cp.hexValue);

            }

             

            ================ below is the xml list

             

            <?xml version="1.0" encoding="utf-8"?>

            <vidlist>

            <!-- All vids ® copyrght Passion Records -->

                <!-- www.passionrecords.com -->       

               

                <vid>

                    <file>/video/solution2.f4v</file>

                    <name>7 Possible Solutions (mvmt.2)</name>

                </vid>   

               

                <vid>

                    <file>/video/solution4.f4v</file>

                    <name>Hope (excerpt)</name>

                </vid>

               

                <vid>

                    <file>/video/perahara1.f4v</file>

                    <name>Kandy Perhara</name>

                </vid>   

               

                <vid>

                    <file>/video/perahara2.f4v</file>

                    <name>Filmed in Kandy Sri Lanka</name>

                </vid>   

               

                <vid>

                    <file>/video/perahara3.f4v</file>

                    <name>The Perahara Festival</name>

                </vid>   

               

                <vid>

                    <file>/video/perahara4.f4v</file>

                    <name>Perahara Festival day 3</name>

                </vid>   

               

                <vid>

                    <file>/video/solution5.f4v</file>

                    <name>Nan Jing in Performance</name>

                </vid>   

             

               

            </vidlist>

            • 3. Re: Loading the vidlist.xml file with ActionScript
              kglad Adobe Community Professional & MVP

              use the trace function to debug:

               

              import fl.controls.ColorPicker;

              import fl.events.ColorPickerEvent;

              import fl.events.SliderEvent;

              import fl.video.FLVPlayback;

              import fl.video.VideoEvent;

               

              var vidList_XML:XML;

              var vidTitle:String;

              var count:int = 0;

              var xmlLoader:URLLoader = new URLLoader();

              xmlLoader.load(new URLRequest("vidlist.xml"));

              xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

               

              function xmlLoaded(event:Event):void {

                  vidList_XML = new XML(xmlLoader.data);

                  vidPlayer.addEventListener(VideoEvent.COMPLETE, changeVid);

                  title_txt.text = "This is the first Video File";

              }

               

              function changeVid(e:VideoEvent):void {

                  var nextVid:String = "../video/"+vidList_XML.vid[count].file;

              trace("nextVid: ",nextVid);  // when the first video completes play, do you see any trace?  if not, vidPlayer is incorrect or the video is completing before the xml completes loading.  if yes, is the nextVid value what you expect?

                  vidPlayer.source = nextVid;

                  vidTitle = vidList_XML.vid[count].name;

                  title_txt.text = vidTitle;

                  vidPlayer.skinBackgroundColor = Math.random() * 0xFFFFFF;

                  count++;

              }

               

              alphaSlide.addEventListener(SliderEvent.CHANGE, alphaChange);

               

              function alphaChange(e:SliderEvent):void {

                  vidPlayer.skinBackgroundAlpha = e.target.value;

              }

               

              colorChoose.addEventListener(ColorPickerEvent.CHANGE, changeHandler);

               

              function changeHandler(e:ColorPickerEvent):void {

                  var cp:ColorPicker = e.currentTarget as ColorPicker;

                  vidPlayer.skinBackgroundColor = Number("0x" + cp.hexValue);

              }

               

              ================ below is the xml list

               

              <?xml version="1.0" encoding="utf-8"?>

              <vidlist>

              <!-- All vids ® copyrght Passion Records -->

                  <!-- www.passionrecords.com -->       

                 

                  <vid>

                      <file>/video/solution2.f4v</file>

                      <name>7 Possible Solutions (mvmt.2)</name>

                  </vid>   

                 

                  <vid>

                      <file>/video/solution4.f4v</file>

                      <name>Hope (excerpt)</name>

                  </vid>

                 

                  <vid>

                      <file>/video/perahara1.f4v</file>

                      <name>Kandy Perhara</name>

                  </vid>   

                 

                  <vid>

                      <file>/video/perahara2.f4v</file>

                      <name>Filmed in Kandy Sri Lanka</name>

                  </vid>   

                 

                  <vid>

                      <file>/video/perahara3.f4v</file>

                      <name>The Perahara Festival</name>

                  </vid>   

                 

                  <vid>

                      <file>/video/perahara4.f4v</file>

                      <name>Perahara Festival day 3</name>

                  </vid>   

                 

                  <vid>

                      <file>/video/solution5.f4v</file>

                      <name>Nan Jing in Performance</name>

                  </vid>   

               

                 

              </vidlist>

              • 4. Re: Loading the vidlist.xml file with ActionScript
                softkens01 Level 1

                Hello Kglad,

                 

                Thank you for your prompt reply. Yes, the next video is traced and even the skinBackgroundColor changed accordingly but the next video "nextVid" is not displaying in vidPlayer. Each video is at leat 2 minutes.  As defined, vidPlayer is supposed to display all videos listed in xml list.

                • 5. Re: Loading the vidlist.xml file with ActionScript
                  kglad Adobe Community Professional & MVP

                  what's your url?

                  • 6. Re: Loading the vidlist.xml file with ActionScript
                    softkens01 Level 1

                    Hello Kglad,

                     

                    I have found the problem, it was  this declaration: var nextVid:String = "../video/"+vidList_XML.vid[count].file;

                    It should be: var nextVid:String = vidList_XML.vid[count].file; It working fine now. Thank you.