|
-
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, -40, 40, 1, true);
yScaleT.onMotionFinished = function() {
_root.test = random(2);
//
if (_root.test == 0){
var yScaleT:Tween = new Tween(this, "_rotation", Strong.easeInOut, -40, 40, 1, true);
} else if (_root.test == 1){
var yScaleT:Tween = new Tween(this, "_rotation", Strong.easeInOut, -20, 20, 1, true);
}
What I want is different tweens on the same mc playing radom, after eachother?
Anyone?
Thanx!
-
-
Flash/Flex Developer
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.
-
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, -40, 40, 1, true);
yScaleT.onMotionFinished = function() {
callNextTween();
trace("finished start");
};
function callNextTween() {
var rndNum = random(2);
switch (rndNum) {
case 0 :
var yScaleT:Tween = new Tween(myBox, "_rotation", Strong.easeInOut, -40, 40, 1, true);
trace("zero");
break;
case 1 :
var yScaleT:Tween = new Tween(myBox, "_rotation", Strong.easeInOut, -20, 20, 1, true);
trace("one");
break;
}
}
-
Never mind! got it! 
PHP Code:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var yScaleT:Tween = new Tween(myBox, "_x", Strong.easeInOut, -40, 40, 2, true);
yScaleT.onMotionFinished = function() {
trace("finished start");
callNextTween();
};
function callNextTween() {
var rndNum = random(2);
switch (rndNum) {
case 0 :
var yScaleP:Tween = new Tween(myBox, "_rotation", Strong.easeInOut, -40, 40, 1, true);
trace("zero");
//einde();
break;
case 1 :
var yScaleP:Tween = new Tween(myBox, "_rotation", Strong.easeInOut, -20, 20, 1, true);
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|