1 Reply Latest reply on May 30, 2008 7:10 AM by Ankur Arora

    Start an actionscript tween when movie loads

    Level 7
      I am trying to get this flash file to start my motion tween that i have done in
      actionscipt to play once the movie plays, but i can only seem to get it to work
      if i do an onRollOver or onPress. I would also like to add in a Roll Over state
      that will enlarge the photo slightly. Any help will be greatly appreciated..

      This is code in flash file:
      var images:Array = new Array (new Array("Aspen","Picture 1.png"), new
      Array("Steamboat","Picture 2.png"), new Array("Breck","Picture 3.png"));
      //var tween:Tween = new Tween(

      // The AlphaTween.as Actionscript will run the show.
      #include "AlphaTween.as"
      // and call its main function
      main();


      //create text
      _root.createTextField("vid12",4,28.5,163.5,81,20);
      _root.createTextField("vid22",5,169.5,173.5,15,100);
      _root.createTextField("vid32",6,310.5,173.5,15,100);

      myformat = new TextFormat();
      myformat.size = 13;
      myformat.align = "center";



      //load text
      vid12.text = images[0][0];
      vid12.setTextFormat(myformat);


      This is code in external file:

      import mx.transitions.Tween;
      import mx.transitions.easing.*;

      // Global variables
      var alphaStart = 0; // Start with an alpha value of 20%

      function main(){
      getImage();
      }
      function getImage(){
      //create MC
      this.createEmptyMovieClip("vid10", this.getNextHighestDepth());
      vid10.createEmptyMovieClip("vid11", this.getNextHighestDepth());

      this.createEmptyMovieClip("vid20", this.getNextHighestDepth());
      vid20.createEmptyMovieClip("vid21", this.getNextHighestDepth());

      this.createEmptyMovieClip("vid30", this.getNextHighestDepth());
      vid30.createEmptyMovieClip("vid31", this.getNextHighestDepth());

      //load images
      vid10.vid11.loadMovie(images[0][1]);
      vid20.vid21.loadMovie(images[1][1]);
      vid30.vid31.loadMovie(images[2][1]);

      //pics location
      vid10._x = 28.5
      vid10._y = 77.5


      vid20._x = 169.5
      vid20._y = 77.5


      vid30._x = 310.5
      vid30._y = 77.5


      // Default start value for alpha
      vid10._alpha = alphaStart;
      vid20._alpha = alphaStart;
      vid30._alpha = alphaStart;

      // OnRollOver action to start doTween
      vid10.onRollOver = doTween;
      vid20.onRollOver = doTween;
      vid30.onRollOver = doTween;

      }

      // Do the combination tween on the MovieClip
      function doTween(){


      var mcAlpha:Tween =
      new Tween( vid10, "_alpha" ,
      Strong.easeIn, alphaStart, 70, 2, true );

      var mcAlpha:Tween =
      new Tween( vid20, "_alpha" ,
      Strong.easeIn, alphaStart, 70, 2, true );


      var mcAlpha:Tween =
      new Tween( vid30, "_alpha" ,
      Strong.easeIn, alphaStart, 70, 2, true );

      };

        • 1. Start an actionscript tween when movie loads
          Ankur Arora Level 1
          Hi,
          For using tween on images instead of rollover event, you have to use MovieClipLoader class or onEnterFrame that will tell you that loading of images has been done or not. As soon event of loading completion executes you can create new Tween on to that object.

          And for zooming you can use _xscale and _yscale properties in Tween class. This you can do on rollover of the buttons.

          In case I'm not clear, send me the FLA file and images. I'll change the code for you.




          Thanks & Regards
          Ankur Arora
          Project Leader(Flash and Flex)
          http://flashdeveloper.blogspot.com
          let your thoughts fly to others... you will become rich.