1 Reply Latest reply on Sep 18, 2010 6:40 AM by wario2010

    Xml slideshow playback controls issue

    wario2010

      Hi, I'm trying to create a picture slideshow which can be controled by the user with play / stop / next buttons. I've managed to program the play / stop events with success, but I'm stuck trying to create the next button event since it doesn´t work properly. The first time I hit the next button it takes me to the same picture that has been currently loaded, the second time I hit the next button it works as expected, takes me to the next image.

      I appreciate your help, thank you in advance.

       

       

      Here's the Code:

       

      import fl.transitions.Tween;
      import fl.transitions.easing.*;
      import fl.transitions.TweenEvent;

       

      stop();

       

      //Escondo botones navegación
      navigation.visible = false;

       

      //Declaro/inicio variables
      var loadernike:loadercreditos = new loadercreditos();
      var my_speed:Number;
      var my_total:Number;
      var my_images:XMLList;
      var my_loaders_array:Array = [];
      var my_labels_array:Array = [];
      var my_success_counter:Number = 0;
      var my_playback_counter:Number = 0;
      var my_contador_next:Number = 0;
      var my_slideshow:Sprite = new Sprite();
      var my_image_slides:Sprite = new Sprite();
      var my_label_slides:Sprite = new Sprite();
      var my_preloader:TextField;
      var my_timer:Timer;
      var my_prev_tween:Tween;
      var my_tweens_array:Array = [];
      var my_xml_loader:URLLoader = new URLLoader();

       

      //Precarga xml
      my_xml_loader.load(new URLRequest("images/interior/NIKE/slideshow.xml"));
      my_xml_loader.addEventListener(Event.COMPLETE, processXML);

       

      var htmlContent:TextField;

       

      function processXML(e:Event):void
      {
          var my_xml:XML = new XML(e.target.data);
          my_xml.ignoreWhitespace = true;
          //htmlContent = my_xml.title.text();

       

          my_speed = my_xml. @ SPEED;
          my_images = my_xml.IMAGE;
          my_total = my_images.length();
          loadImages();
          trace("imag", my_images);
          my_xml_loader.removeEventListener(Event.COMPLETE, processXML);
          my_xml_loader = null;

       

      }

       

      function loadImages():void
      {
          for (var i:Number = 0; i < my_total; i++)
          {
              var my_url:String = my_images[i]. @ URL;
              var my_loader:Loader = new Loader();
              my_loader.load(new URLRequest(my_url));
              my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
              my_loaders_array.push(my_loader);

       

              //formateo texto;
              var myFont = new Font1();
              var myFormat:TextFormat = new TextFormat();
              myFormat.align = TextFormatAlign.RIGHT;
              myFormat.font = myFont.fontName;
              var my_label:TextField = new TextField();
              my_label.textColor = 0xffffff;
              my_label.embedFonts = true;
              my_label.antiAliasType = AntiAliasType.ADVANCED;
              my_label.defaultTextFormat = myFormat;
              my_label.text = my_images[i]. @ TITLE;
              //my_label.autoSize = TextFieldAutoSize.LEFT;
              my_label.width = 450;
              my_label.background = true;
              my_label.border = true;
              my_label.backgroundColor = 0x000000;

       

              //my_label.htmlText = htmlContent;// Assign the HTML content to the text field*/
              my_labels_array.push(my_label);

       

              //preloader;
              addChild(loadernike);
              loadernike.x = (stage.stageWidth - loadernike.width)/2;
              loadernike.y = (stage.stageHeight - loadernike.height)/2 + 50;
          }
      }

       

      function onComplete(e:Event):void
      {
          my_success_counter++;
          if (my_success_counter == my_total)
          {
              startShow();
          }

       

          var my_loaderInfo:LoaderInfo = LoaderInfo(e.target);
          my_loaderInfo.removeEventListener(Event.COMPLETE, onComplete);

       

      }

       

      function startShow():void
      {

       

          removeChild(loadernike);
          loadernike = null;
          //muestro botones navegacion
          navigation.navintback.visible = false;
          navigation.visible = true;

       

          addChild(my_slideshow);
          my_slideshow.addChild(my_image_slides);
          my_slideshow.addChild(my_label_slides);
          my_slideshow.x = 30;
          my_slideshow.y = 160;

       

          nextImage();

       


          my_timer = new Timer(my_speed * 1000);
          my_timer.addEventListener(TimerEvent.TIMER, timerListener);
          my_timer.start();

       


          //boton stop;
          function clickstopboton(event:MouseEvent):void
          {
              navigation.navintnext.gotoAndStop(1);

       

              if (MisGlobales.vars.i == 0 && MisGlobales.vars.h != 1)
              {
                  navigation.navint.gotoAndPlay(2);
                  my_timer.stop();

       

              }
              else if (MisGlobales.vars.i==1 && MisGlobales.vars.h != 1)
              {
                  //play
                  navigation.navint.gotoAndPlay(1);

       

                  my_timer.start();
              }

       

              if (MisGlobales.vars.h == 1 && MisGlobales.vars.i == 0)
              {
                  navigation.navint.gotoAndStop(2);
                  my_timer.stop();

       

              }
              else if ( MisGlobales.vars.h == 1 && MisGlobales.vars.i == 1 )
              {
                  navigation.navint.gotoAndStop(1);


              }

       

          }

       

          navigation.navint.addEventListener(MouseEvent.CLICK, clickstopboton);
          navigation.navint.buttonMode = true;

       

          //boton next;
          function clicknextboton(event:MouseEvent):void
          {

       

              my_timer.stop();
              navigation.navint.gotoAndStop(2);

       

              nextImage();
              my_playback_counter++;

       

              trace("playback_counter_next",my_playback_counter);
              if (my_playback_counter == my_total)
              {
                  my_playback_counter = 0;

       

              }

       

          }

       

          navigation.navintnext.addEventListener(MouseEvent.CLICK, clicknextboton);
          navigation.navintnext.buttonMode = true;

       

          //boton back;
          function clickbackboton(event:MouseEvent):void
          {
              my_timer.stop();
              nextImage();
              my_playback_counter--;

       


              if (my_playback_counter == 0)
              {
                  my_playback_counter = my_total;
                  my_timer.stop();
              }

       

          }

       

          navigation.navintback.addEventListener(MouseEvent.CLICK, clickbackboton);
          navigation.navintback.buttonMode = true;

       

          //slide auto
          function nextImage():void
          {
              var my_image:Loader = Loader(my_loaders_array[my_playback_counter]);
              my_image_slides.addChild(my_image);
              my_tweens_array[0] = new Tween(my_image,"alpha",Strong.easeOut,0,1,1,true);

       

              var my_label:TextField = TextField(my_labels_array[my_playback_counter]);
              my_label_slides.addChild(my_label);
              my_label.x=(stage.stageWidth - 63) - my_label.width;
              my_label.y=(my_image.y+my_image.height)+7;
              my_tweens_array[1] = new Tween(my_label,"alpha",Strong.easeOut,0,1,1,true);

       

          }

       

          function timerListener(e:TimerEvent):void
          {
              hidePrev();
              my_playback_counter++;
              if (my_playback_counter == my_total)
              {
                  my_playback_counter = 0;
              }
              nextImage();
              trace("playback_counter_play",my_playback_counter);

       

          }

       

          function hidePrev():void
          {
              var my_image:Loader = Loader(my_image_slides.getChildAt(0));
              my_prev_tween = new Tween(my_image,"alpha",Strong.easeOut,1,0,1,true);
              my_prev_tween.addEventListener(TweenEvent.MOTION_FINISH, onFadeOut);

       

              var my_label:TextField = TextField(my_label_slides.getChildAt(0));
              my_tweens_array[2] = new Tween(my_label,"alpha",Strong.easeOut,1,0,1,true);

       

          }

       

          function onFadeOut(e:TweenEvent):void
          {
              my_image_slides.removeChildAt(0);
              my_label_slides.removeChildAt(0);
          }
          function clickbotonskb(event:MouseEvent):void
          {
              my_timer.removeEventListener(TimerEvent.TIMER, timerListener);
              gotoAndPlay(10);
              MovieClip(root).main.main_bar.seccinteriors.my_playback_counter_sk = 0;
          }

       

          skunkfunk_btn.addEventListener(MouseEvent.CLICK, clickbotonskb);
          skunkfunk_btn.buttonMode = true;

       

      }

       

       

      See example at:

       

      http://www.neoconfort.com/neoconfort/Neoconfort.html