A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: looping tween class

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326

    looping tween class

    I've used the Tween Class to put together an image gallery scroller. As you can see in attached example the top 3 images are the same as the bottom 3. For a reason. The tween class shifts the images from top to bottom. At which point the total images clip should shift back to the top and continue from there. These would make it appear as if the images rotate.

    I've used this code:
    Actionscript Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    //
    var myTween:Tween = new Tween(img1_mc, "_y", Elastic.easeOut, 0, 0, 2, true);
    myTween.onMotionFinished = function() {
        var myFinish:Number = img1_mc._y-160;
        var myDuration:Number = 2;
        if (myFinish == -1120) {
            img1_mc._y = 0;
            var myFinish:Number = img1_mc._y-160;
        }
        myTween.continueTo(myFinish,myDuration);
    };
    So when img1_mc reaches the _y of -1120 it has reached the bottom 3 duplicate images. And then moves back to 0 to the top 3 images. Which are exactly the same. So when the tween repeats from there again it would seem as the images would rotate. Instead of going top to bottom and moving to top again.

    But it doesn't work. Even when I use img1_mc._y to 0 it probably does that, but the continueTo still starts the tween from its last position -1120 to -160. Instead of first setting y to 0 and then continue the tween from 0 to -160.

    I've tried using start(), repeat() etc. but can't get it to work. What must I do?

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

  2. #2
    Senior Member
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    326
    Already found out a better way:
    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    slider();
    //
    function slider() {
    	var slide:Tween = new Tween(gallery, "_y", Bounce.easeOut, gallery._y, (gallery._y)-160, 2, true);
    	slide.onMotionFinished = function() {
    		if (gallery._y<=-960) {
    			gallery._y = 0;
    		}
    		slider();
    	};
    }

    Illustration | Animation | Web Banners | Graphic Design
    Ducklord Studio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center