[Tweener] Randomly changing the tweener target
Travis Almand
travisalmand at yahoo.com
Thu Jul 10 06:44:21 PDT 2008
>From what I see not much will happen because you're trying to pass a variable that doesn't exist unless you declare it outside the function like you said you tried. But if you declare it outside the function and assign zero to it then that's all that's going to get passed. Plus, I don't think Tweener is made to handle values returned from a function so nothing is going to happen anyway.
This is what I would do. Create a function that handles almost everything in itself and just call that function at end of the tween. In the function create your random number, grab the clip from the array with the random number and tween the clip. If you want it to loop then make the tween inside the function call the same function at the end. To get things rolling you only have to call the function once and it should handle itself from there.
This would loop indefinitely unless you killed it somehow such as maybe manually killing the tween or putting the tween inside an if statement that tests whether a variable is true or false. If the variable is true then start the tween. When you want the tween to stop, make the variable false. It should stop since the next time the function is called then the tween won't start, killing the loop.
Of course, this is all said without writing a line of code to verify this would all actually work as described. Your results may vary.
travis
----- Original Message ----
From: Jarryd (hotmail) <yaheed at hotmail.com>
To: tweener at lists.caurinauebi.com
Sent: Thursday, July 10, 2008 2:15:59 AM
Subject: [Tweener] Randomly changing the tweener target
Hello and thanks for your help,
What I have is an array of the paths
to movieclips that are on my stage.
(AS3)
var productArray:Array = new
Array(products.image1, products.image2, products.image3);
Now what I want to do is use this array to pick a
random movieclip and tween it in and out after another movieclip has tweened in.
Eg
Tweener.addTween(movieClipOne,
{x: xValue, y: yValue, alpha: alphaValue, onComplete: Randomise,
onCompleteParams: [i] });
Tweener.addTween(productArray[i],
{x: xValue, y: yValue, alpha: alphaValue});
What randomises the value i is a Randomise function I've declared on the onComplete parameter:
function Randomise():Number {
var i:Number =
0;
num =
Math.round(Math.random() * 2); // Because num should be 0 - 2 with
regards to the array
i =
num;
return i;
}
This came up with undeclared variables errors, so I
set the
var i:Number = o
outside of the function as well. I've traced the I
variable inside the function and outside, and they obviously come up with 2
different numbers...one being the random and the other being 0.
The code in total looks like this:
var i:Number = o
var productArray:Array = new
Array(products.image1, products.image2, products.image3);
Tweener.addTween(movieClipOne,
{x: xValue, y: yValue, alpha: alphaValue, onComplete: Randomise,
onCompleteParams: [i] });
Tweener.addTween(productArray[i],
{x: xValue, y: yValue, alpha: alphaValue});
function Randomise():Number {
var i:Number =
0;
num =
Math.round(Math.random() * 2);
i =
num;
return i;
}
So yeah this doesn't work which is the reason why
I'm asking for help :P. There are no compiling errors, it comes up with
the runtime error:
## [Tweener] Error: [object MovieClip]
raised an error while executing the 'onComplete'handler.
ArgumentError:
Error #1063: Argument count mismatch on flashdoc_fla::MainTimeline/Randomise().
Expected 0, got 1.
at
Function/http://adobe.com/AS3/2006/builtin::apply()
at
caurina.transitions::Tweener$/updateTweenByIndex()
at
caurina.transitions::Tweener$/updateTweens()
at
caurina.transitions::Tweener$/onEnterFrame()
Thanks for any help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20080710/d6f4d46f/attachment-0001.htm>
More information about the Tweener
mailing list