[Tweener] Randomly changing the tweener target
Zeh Fernando
zeh at zehfernando.com
Thu Jul 10 06:35:27 PDT 2008
Hi Jarryd,
> 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:
Because honestly that code isn't correct. You're calling a function on
onComplete, but that function simply generates a number. Then you're
trying to pass an argument to that function, and not only an argument
that doesn't exist, but that function doesn't take an argument either.
Since your animation doesn't seem to have any time, you can just do this:
Tweener.addTween(movieClipOne, {x: xValue, y: yValue, alpha: alphaValue});
Tweener.addTween(productArray[Randomise()], {x: xValue, y: yValue,
alpha: alphaValue});
If it does take some time, you just add the time as a delay:
Tweener.addTween(movieClipOne, {x: xValue, y: yValue, alpha: alphaValue,
time:1});
Tweener.addTween(productArray[Randomise()], {x: xValue, y: yValue,
alpha: alphaValue, delay:1});
If you REALLY need the thing to be executed onComplete, then there's a
number ways to do it, like
Tweener.addTween(movieClipOne, {x: xValue, y: yValue, alpha: alphaValue,
onComplete:secondFunc, onCompleteScope:this});
function secondFunc(): void {
Tweener.addTween(productArray[Randomise()], {x: xValue, y: yValue,
alpha: alphaValue});
}
Really, calling Randomise() onComplete does absolutely nothing. It
generates and destroys a number. It doesn't change the value of the 'i'
variable.
Zeh
More information about the Tweener
mailing list