0 Replies Latest reply on Jun 14, 2010 1:34 PM by SpiritOfTheWinds

    Need help to convert from AS3 to AS2

    SpiritOfTheWinds Level 1

      Okay, instead of my last post which I was looking for a AS2 slideshow sollution, I got this code in AS3 which would be easier to convert into AS2. I know it should work since I have the .fla in AS3. Thanks!

       

      ( I know that a big part will not change, but I would like you to change what should be changed. )

       

      import com.greensock.*;

      var imageLoader:Loader = new Loader();
      var imageLoader2:Loader = new Loader();
      var myTween:TweenLite;
      var myImages_array:Array = new Array;

      var myImages = ""; // Should be like "1.jpg|2.jpg|3.jpg|4.jpg" (from a  text file)
      var myDelay = 5;
      var img = 0;
      var ordre = 0;
      var image_total = 0;

      function init_slideshow()
      {
           myImages_array = myImages.split("|");
           image_total = myImages_array.length;

           load_image(imageLoader,img);
           load_image(imageLoader2,img+1);

           img = img + 1;
          
           animate_slideshow();
      }

      function animate_slideshow()
      {
         if(ordre == 0)
         {
             myTween = new TweenLite(myLoader, 2, {alpha:0,delay:myDelay,  onComplete:next_slide});
         }
         else
         {
             myTween = new TweenLite(myLoader2, 2, {alpha:0,delay:myDelay,  onComplete:next_slide});
         }
      }

      function next_slide()
      {   
           if(img >= image_total-1)
           {
               img = -1;
           }
          
           if(ordre == 0)
               {
               setChildIndex(myLoader,0);
               setChildIndex(myLoader2,1);
                      
               myLoader.alpha = 1;
               load_image(imageLoader,img+1);
               img = img + 1;

               ordre = 1;
           }
           else
           {
               setChildIndex(myLoader,1);
               setChildIndex(myLoader2,0);
                      
               myLoader2.alpha = 1;
               load_image(imageLoader2,img+1);
               img = img + 1;

               ordre = 0;   
           }
          
           animate_slideshow();
      }

      function load_image(myMc,img)
      {
           myMc.unload();

           if(ordre == 0)
               {
               for(var i:uint = 0; i < myLoader.numChildren; i++){
                  myLoader.removeChildAt(i);
               }
           }
           else
           {
               for(var z:uint = 0; z < myLoader2.numChildren; z++){
                     myLoader2.removeChildAt(z);
               }
           }
          
           myMc.load(new URLRequest("MyImagesURL/images/" +  myImages_array[img]));   
      }

      function hide_image()
      {
           if(img == myImages_array.length - 1)
           {
               img = 0;
           }
           else
           {
               img = img + 1;
           }
          
           myTween = new TweenLite(myLoader, 5, {alpha:0,delay:myDelay,  onComplete:load_image, onCompleteParams:[img]});
      }

      imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,  function(e:Event){
         myLoader.addChild(e.target.content);    
      });

      imageLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE,  function(e:Event){
         myLoader2.addChild(e.target.content);
      });

      myLoader.x = 0;
      myLoader.y = 0;

      myLoader2.x = 0;
      myLoader2.y = 0;

      var url:String = "myURL";
      var loadit:URLLoader = new URLLoader();
      loadit.addEventListener(Event.COMPLETE, completeHandler);
      loadit.load(new URLRequest(url));

      function completeHandler(event:Event):void {
        myImages = event.target.data;
        init_slideshow();

      }

       

      As for now, I have this (which is the last part  of the code above):

       

      rnd =  Math.floor(Math.random()*100000000);
      url = site_root + "/handler.ashx?id=" + _root.myid + "&rn="+rnd;  //Any existant image in the folder

      var sendLV:LoadVars=new LoadVars();
      var receiveLV:LoadVars=new LoadVars();
          
      receiveLV.onData=function(src){

          myImages = src;
           init_slideshow();

      }
          
      sendLV.sendAndLoad(url,receiveLV,"POST");