0 Replies Latest reply on Jun 8, 2009 8:02 AM by Alpdog14

    Convert AS2 to AS3

    Alpdog14

      I need help converting AS2 to AS3, I have a photo rotating feature that I need in AS3 because I have a RSS feeder that uses AS3 and I want them to be in one flash project. Now I try to install the auto converter but it did not do anything for me so unless someone can tell me how to use that converter, can someone tell what parts of this code have to change so I can use this in AS3. Here is the AS2 for the photo rotater:

       


      stop();
      import mx.transitions.Tween;
      import mx.transitions.easing.*;
      pauls_item._visible = false;
      item_number_group.item_number._visible = false;

      var xml_file:String = "news2.xml";
      var folder:String = "thumbnails/";
      var auto_duration:Number = 6000; // where 1 second equals 1000
      var auto_play:Boolean = true; // true = ON | false = OFF
      var tween_duration:Number = 0.65; // in seconds

      var item_filename:Array = new Array();
      var item_url:Array = new Array();
      var item_url_target:Array = new Array();
      var item_title:Array = new Array();
      var item_description:Array = new Array();
      var total:Number;
      var i:Number;
      var interval_id:Number;
      var current:Number = 0;
      var xml:XML = new XML();

      xml.onLoad = function()
      {
      item_list.p_item._visible = false;
      var nodes = this.firstChild.childNodes;
      total = nodes.length;

      for( i = 0; i < total; i++)
      {
        item_filename[i] = nodes[i].attributes.filename;
        item_url[i] = nodes[i].attributes.url;
        item_url_target[i] = nodes[i].attributes.target;
        item_title[i] = nodes[i].attributes.title;
        item_description[i] = nodes[i].attributes.description;
      }
      create_item_list();
      }
      xml.load( xml_file );
      xml.ignoreWhite = true;

      function create_item_list():Void
      {
      for( i = 0; i < total; i++)
      {
        var item = pauls_item.duplicateMovieClip("p_item"+i, i);
        item.p_pic.loadMovie(folder + item_filename[i]);
        item.p_title.text = item_title[i];
        item.p_description.text = item_description[i];
        item.no = i;
        if( i > 0 )
         item._visible = false;
        
        item.p_button.onRelease = function()
        {
         getURL( item_url[this._parent.no], item_url_target[this._parent.no] );
        }
       
        var mi = item_number_group.item_number.duplicateMovieClip("item_number"+i, i);
        mi.over = true;
        mi.item_label = i + 1;
        mi.item_no = i;
        mi._x = i * 25; // spacing between items
      }
      if( auto_play == true )
      {
        interval_id = setInterval(this, "change_item", auto_duration, "next");
      }
      change_menu_item(0); // the default item on load
      }
      function change_item(command)
      {
      p_previous.enabled = p_next.enabled = false;

       

      for( i = 0; i < total; i++ )
      {
        item_number_group["item_number"+i].pauls_button.enabled = false;
      }
      old_number = current;

       

      if( command == "previous" )
        current--;
      else if( command == "next" )
        current++;
      else
        current = command;

       

      if( current < 0 )
        current = total - 1;
      if( current >= total )
        current = 0;

       

      change_menu_item(current);

       

      old_item = this["p_item" + old_number];
      old_item.p_button.enabled = false;
      new_item = this["p_item" + current];
      new_item.p_button.enabled = true;
      new_item._visible = true;

      var p_tween = new Tween(old_item, "_alpha", Regular.easeInOut, 100, 0, tween_duration, true);
      new Tween(new_item, "_alpha", Regular.easeInOut, 0, 100, tween_duration, true);
      p_tween.onMotionFinished = function()
      {
        p_previous.enabled = p_next.enabled = true;
        for( i = 0; i < total; i++ )
        {
         item_number_group["item_number"+i].pauls_button.enabled = true;
        }
        old_item._visible = false;
      }
      }
      function p_interval()
      {
      if( p_auto._currentframe == 2 )
      {
        interval_id = setInterval(this, "change_item", auto_duration, "next");
      }
      else
      {
        clearInterval(interval_id);
      }
      p_auto.play();
      }
      p_previous.onRelease = function()
      {
      change_item("previous");
      }
      p_next.onRelease = function()
      {
      change_item("next");
      }
      p_auto.onRelease = function()
      {
      this._parent.p_interval();
      }
      if( auto_play == true )
      p_auto.gotoAndStop(1);
      else
      p_auto.gotoAndStop(2);

       

      function change_menu_item(no):Void
      {
      for( i = 0; i < total; i++ )
      {
        var mi = item_number_group["item_number"+i];
        mi.pauls_button._visible = true;
        mi.over = true;
        mi.pauls_button.onRollOver = function()
        {
         this._parent.over = false;
        }
        mi.pauls_button.onRollOut =
        mi.pauls_button.onDragOut = function()
        {
         this._parent.over = true;
        }
        mi.pauls_button.onRelease = function()
        {
         change_item(this._parent.item_no);
         clearInterval(interval_id);  //stops or clears interval stoping rotation
         p_auto.gotoAndStop(2); //turns the pause button to replay
        
        }
        mi.onEnterFrame = function()
        {
         if( this.over == true ) this.prevFrame();
         else this.nextFrame();
        }
      }
      delete item_number_group["item_number"+no].pauls_button.onRollOut;
      item_number_group["item_number"+no].pauls_button._visible = false;
      item_number_group["item_number"+no].over = false;
      }

       

       

      Then on the opening frame on the layer before this one there is this AS:

       

      var p_menu:ContextMenu = new ContextMenu();
      p_menu.hideBuiltInItems(); _root.menu = fm_menu;
      var item:ContextMenuItem = new ContextMenuItem("", pauls);
      p_menu.customItems[0] = item;
      function pauls() { getURL(""); }

       

      I could really use help. Thanks,