3 Replies Latest reply on Sep 29, 2006 6:34 AM by gdmt

    simplify actionscript

    gdmt Level 1
      hi everyone!
      yeah, i'd like to simplify my AS
      this is:

      import mx.transitions.Tween;
      this.snapshot1.photo.loadMovie("image1.jpg");
      this.snapshot2.photo.loadMovie("image2.jpg");
      this.snapshot3.photo.loadMovie("image3.jpg");
      this.snapshot4.photo.loadMovie("image4.jpg");
      this.snapshot5.photo.loadMovie("image5.jpg");
      this.snapshot6.photo.loadMovie("image6.jpg");
      /******************** snapshot1 ********************/
      snapshot1.onRollOver = function() {
      mx.behaviors.DepthControl.bringToFront(this);
      var myTween:Tween = new Tween(snapshot1, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 120, 3, true);
      var myTween:Tween = new Tween(snapshot1, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 120, 3, true);
      }
      snapshot1.onRollOut = function() {
      var myTween:Tween = new Tween(snapshot1, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 100, 3, true);
      var myTween:Tween = new Tween(snapshot1, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 100, 3, true);
      }
      snapshot1.onRelease = function() {
      getURL("image1.jpg", "_blank");
      }
      /******************** snapshot2 ********************/
      snapshot2.onRollOver = function() {
      mx.behaviors.DepthControl.bringToFront(this);
      var myTween:Tween = new Tween(snapshot2, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 120, 3, true);
      var myTween:Tween = new Tween(snapshot2, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 120, 3, true);
      }
      snapshot2.onRollOut = function() {
      var myTween:Tween = new Tween(snapshot2, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 100, 3, true);
      var myTween:Tween = new Tween(snapshot2, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 100, 3, true);
      }
      snapshot2.onRelease = function() {
      getURL("image2.jpg", "_blank");
      }
      /******************** snapshot3 ********************/
      snapshot3.onRollOver = function() {
      mx.behaviors.DepthControl.bringToFront(this);
      var myTween:Tween = new Tween(snapshot3, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 120, 3, true);
      var myTween:Tween = new Tween(snapshot3, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 120, 3, true);
      }
      snapshot3.onRollOut = function() {
      var myTween:Tween = new Tween(snapshot3, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 100, 3, true);
      var myTween:Tween = new Tween(snapshot3, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 100, 3, true);
      }
      snapshot3.onRelease = function() {
      getURL("image3.jpg", "_blank");
      }
      /******************** snapshot4 ********************/
      snapshot4.onRollOver = function() {
      mx.behaviors.DepthControl.bringToFront(this);
      var myTween:Tween = new Tween(snapshot4, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 120, 3, true);
      var myTween:Tween = new Tween(snapshot4, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 120, 3, true);
      }
      snapshot4.onRollOut = function() {
      var myTween:Tween = new Tween(snapshot4, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 100, 3, true);
      var myTween:Tween = new Tween(snapshot4, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 100, 3, true);
      }
      snapshot4.onRelease = function() {
      getURL("image4.jpg", "_blank");
      }
      /******************** snapshot5 ********************/
      snapshot5.onRollOver = function() {
      mx.behaviors.DepthControl.bringToFront(this);
      var myTween:Tween = new Tween(snapshot5, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 120, 3, true);
      var myTween:Tween = new Tween(snapshot5, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 120, 3, true);
      }
      snapshot5.onRollOut = function() {
      var myTween:Tween = new Tween(snapshot5, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 100, 3, true);
      var myTween:Tween = new Tween(snapshot5, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 100, 3, true);
      }
      snapshot5.onRelease = function() {
      getURL("image5.jpg", "_blank");
      }
      /******************** snapshot6 ********************/
      snapshot6.onRollOver = function() {
      mx.behaviors.DepthControl.bringToFront(this);
      var myTween:Tween = new Tween(snapshot6, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 120, 3, true);
      var myTween:Tween = new Tween(snapshot6, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 120, 3, true);
      }
      snapshot6.onRollOut = function() {
      var myTween:Tween = new Tween(snapshot6, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 100, 3, true);
      var myTween:Tween = new Tween(snapshot6, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 100, 3, true);
      }
      snapshot6.onRelease = function() {
      getURL("image6.jpg", "_blank");
      }

      i know that may exist any way to make codes like this shorter, but... :S

      can someone tell me what can i do?
        • 1. Re: simplify actionscript
          TimSymons Level 1
          You can define a class like this:

          import mx.transitions.Tween;
          class MyClass extends MovieClip {

          private var imageName:String;
          private var photo:MovieClip;

          public function MyClass() {
          //
          }

          public function init(fileName:String):Void {
          imageName = fileName;
          this.photo.loadMovie(imageName);
          }

          public function onRollOver():Void {
          mx.behaviors.DepthControl.bringToFront(this);
          var myTween:Tween = new Tween(this, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 120, 3, true);
          var myTween:Tween = new Tween(this, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 120, 3, true);
          }

          public function onRollOut():Void {
          var myTween:Tween = new Tween(snapshot6, "_xscale", mx.transitions.easing.Elastic.easeOut, this._xscale, 100, 3, true);
          var myTween:Tween = new Tween(snapshot6, "_yscale", mx.transitions.easing.Elastic.easeOut, this._yscale, 100, 3, true);
          }

          public function onRelease():Void {
          getURL(imageName, "_blank");
          }
          }

          Then attach this class to the movieClips in the library by right-clicking on them and selecting the linkage item.

          Then in the timeline with each movieclip use the following code:

          this.snapshot1("image1.jpg");
          this.snapshot2("image2.jpg");
          this.snapshot3("image3.jpg");
          this.snapshot4("image4.jpg");
          this.snapshot5("image5.jpg");
          this.snapshot6("image6.jpg");

          Tim
          • 2. Re: simplify actionscript
            gdmt Level 1
            i'll check it
            thanx 4 reply TimSymons!
            • 3. Re: simplify actionscript
              gdmt Level 1
              uhm... it doesn't work...
              could u explain it in detail?