3 Replies Latest reply on Sep 15, 2011 12:11 AM by gajanan hiroji

    Xml file not displaying.

    Teejay011

      Hello all,

      Pls i am trying to work on an example that displays some pics in form of slide show. Everything worked fine till i got to a point of displaying the content of an xml file. I tried all i could but things did not work out. someone pls help, i am frustrated. Below re my codes.

      ----------------------------------------------------------------------------

      test.xml

      -------------

       

      <?xml version="1.0"?>

      <wedshow>

       

      <audio source="devpics/mus.mp3 />

      <photo duration="10" source="devpics/test.jpg" />

      <photo duration="20" source="devpics/tes.jpg" />

      <photo duration="20" source="devpics/testA.jpg" />

      </wedshow>

       

       

      ------------------------------------------------------------------------------

      WedShowPlayer2.mxml

      ----------------------------------

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

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:MyComp="*" layout="absolute" initialize="init();">

       

      <mx:Script>

      <![CDATA[

      import mx.rpc.events.ResultEvent;

      private function init():void {

      service.send();

      }

      ]]>

      </mx:Script>

      <mx:HTTPService id="service" url="component/test.xml" resultFormat="e4x" result="show.loadShow(

      XML(event.result) ); show.playShow();" />

       

      <MyComp:WedShow id="show" width="100%" height="100%" horizontalCenter="0"/>

       

      </mx:Application>

      ------------------------------------------------------------------------------------------ ----------------------------------
      WedShow.mxml
      ------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off" verticalScrollPolicy="off">
      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      import flash.display.Loader;
      [Bindable]
      private var _xml:XML;
      private var photos:ArrayCollection = new ArrayCollection();
      private var sound:Sound;
      private var iLoaded:uint = 1;
      private var isLoaded:Boolean = false;
      private var timer:Timer = new Timer(1000,0);
      private var photoIndex:int = 0;
      private var nextPhotoTime:int = 1;
      public function playShow():void {
      if(isLoaded) {
      play.visible = false;
      timer = new Timer(1000,0);
      timer.addEventListener( TimerEvent.TIMER, onTime );
      timer.start();
      if(sound!=null) {sound.play();}
      } else { loadShow( _xml ); }
      }
      private function onTime( event:TimerEvent ):void {
      if( event.currentTarget.currentCount == nextPhotoTime ) {
      if( photos.length > photoIndex ) {
      image.load(Loader(photos[photoIndex]).content);
      // using e4x to access the photo duration attribute
      nextPhotoTime += int(_xml.photo[photoIndex].@duration);
      photoIndex++;
      } else {
      stopShow();
      }
      }
      }
      public function stopShow():void {
      timer.stop();
      timer.reset();
      image.source="";
      SoundMixer.stopAll();
      photoIndex = 0;
      nextPhotoTime = 1;
      play.visible = true;
      }
      public function loadShow( xml:XML ):void {
      _xml = xml;
      photos = new ArrayCollection();
      iLoaded = 1;
      isLoaded = false;
      photoIndex = 0;
      nextPhotoTime = 1;
      progress.visible = true;
      play.visible = false;
      for each(var photoNode:XML in _xml.photo) {
      var photo:Loader = new Loader();
      photo.load(new URLRequest(photoNode.@source));
      photo.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
      onProgress);
      photo.contentLoaderInfo.addEventListener(Event.COMPLETE,
      onComplete);
      photos.addItem(photo);
      }
      progress.label="Loading Image " + iLoaded +" of " + photos.length + ".";
      }
      private function onProgress( event:ProgressEvent ):void {
      var loaded:Number = 0;
      var total:Number = 0;
      if(iLoaded<photos.length) {
      for each(var item:Loader in photos) {
      loaded += item.contentLoaderInfo.bytesLoaded;
      total += item.contentLoaderInfo.bytesTotal;
      }
      } else {
      loaded = event.bytesLoaded;
      total = event.bytesTotal;
      }
      progress.setProgress(loaded,total);
      }
      private function onComplete( event:Event ):void {
      if(iLoaded<photos.length) {
      iLoaded++;
      progress.label="Loading Image " + iLoaded + "of" +
      photos.length;
      } else if (sound==null && _xml.audio[0].@source!="") {
      sound = new Sound();
      sound.addEventListener(ProgressEvent.PROGRESS, onProgress);
      sound.addEventListener(Event.COMPLETE, onComplete);
      sound.load(new URLRequest(_xml.audio[0].@source));
      progress.label="Loading Audio";
      } else {
      progress.visible = false;
      play.visible = true;
      isLoaded = true;
      }
      }
      ]]>
      </mx:Script>
      <mx:LinkButton id="play" label="Play" horizontalCenter="0" verticalCenter="0" visible="false" color="0xFFFFFF" />
      <mx:ProgressBar id="progress" mode="manual" width="60%" horizontalCenter="0" verticalCenter="0" color="0xFFFFFF" />
      <mx:Image id="image" horizontalCenter="0" verticalCenter="0"/>
      </mx:Canvas>
      ------------------------------------------------------------------------------------------ -------------------------------------------------------------
      anyone pls help
      thanks in anticipation