A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: random Tweening with the Tween Class

  1. #1

    Unhappy random Tweening with the Tween Class

    Hi all,

    I'm getting %@!#!#!@
    I have a mc and I want to use the Tweenclass in it.
    I want the mc to do random things. I tried everything i guess, just not the right thing

    my last code:

    PHP Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;

    var 
    yScaleT:Tween = new Tween(this"_rotation"Strong.easeInOut, -40401true);
    yScaleT.onMotionFinished = function() {
        
    _root.test random(2);
        
    //
    if (_root.test == 0){
        var 
    yScaleT:Tween = new Tween(this"_rotation"Strong.easeInOut, -40401true);
    } else if (
    _root.test == 1){
        var 
    yScaleT:Tween = new Tween(this"_rotation"Strong.easeInOut, -20201true);

    What I want is different tweens on the same mc playing radom, after eachother?

    Anyone?

    Thanx!

  2. #2
    no one

  3. #3
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    I'm a little confused.....you want tweens to be executed in random order?

    You are close......I'm assuming you're using AS 2.0. Try this:

    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    
    var yScaleT:Tween = new Tween(myBox, "_rotation", Strong.easeInOut, -40, 40, 1, true);
    yScaleT.onMotionFinished = function() {callNextTween();}
       
    function callNextTween()
    {
    	 var rndNum = random(2);
    	 
    	 switch(rndNum)
    	 {
    		case 1:
    			var yScaleT:Tween = new Tween(myBox, "_rotation", Strong.easeInOut, -40, 40, 1, true);
    			break;
    		case 2:
    			var yScaleT:Tween = new Tween(myBox, "_rotation", Strong.easeInOut, -20, 20, 1, true);
    			break;
    	 }
    }
    I separated my code and placed it on the main timeline and just inserted my object (myBox) for this.
    Last edited by samac1068; 05-04-2009 at 08:30 PM.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  4. #4
    Hi Samac,

    Thanks for your reply.!
    It plays another tween now after the first one (changed case 1&2 to 0&1)

    After this the animation stops. Do you know how I can get this thing to loop?
    code for now:
    PHP Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    var 
    yScaleT:Tween = new Tween(myBox"_rotation"Strong.easeInOut, -40401true);
    yScaleT.onMotionFinished = function() {
        
    callNextTween();
        
    trace("finished start");
    };
    function 
    callNextTween() {
        var 
    rndNum random(2);
        switch (
    rndNum) {
        case 
    :
            var 
    yScaleT:Tween = new Tween(myBox"_rotation"Strong.easeInOut, -40401true);
            
    trace("zero");
            break;
        case 
    :
            var 
    yScaleT:Tween = new Tween(myBox"_rotation"Strong.easeInOut, -20201true);
            
    trace("one");
            break;
        }


  5. #5
    Never mind! got it!

    PHP Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    var 
    yScaleT:Tween = new Tween(myBox"_x"Strong.easeInOut, -40402true);
    yScaleT.onMotionFinished = function() {
        
    trace("finished start");
        
    callNextTween();
    };
    function 
    callNextTween() {
        var 
    rndNum random(2);
        switch (
    rndNum) {
        case 
    :
            var 
    yScaleP:Tween = new Tween(myBox"_rotation"Strong.easeInOut, -40401true);
            
    trace("zero");
            
    //einde();
            
    break;
        case 
    :
            var 
    yScaleP:Tween = new Tween(myBox"_rotation"Strong.easeInOut, -20201true);
            
    trace("one");
            
    //einde();
            
            
    break;
            
        }
        
    yScaleP.onMotionFinished = function() {
        
    trace("finished start2");
        
    callNextTween();
    };


Tags for this Thread

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