-
stop tween?
Hi
I have a MovieClip that moves to where the mouse was last clicked.
I also want this MovieClip to stop when it comes into contact with another MovieClip. I'm doing this via hitTestObject.
This all works fine, but, I can only get either the X or the Y tween to stop.
I can't get them both to stop?
Code:
// Zac Move
stage.addEventListener(MouseEvent.MOUSE_DOWN, MoveZac);
function MoveZac(event:MouseEvent):void
{
dylan.play();
if(mouseX > zac.x){
zac.gotoAndStop("zacRight");
}else{
zac.gotoAndStop("zacLeft");
}
var zacTweenX:Tween = new Tween(zac, "x", Regular.easeOut, zac.x, mouseX, 1, true);
var zacTweenY:Tween = new Tween(zac, "y", Regular.easeOut, zac.y, mouseY, 1, true);
var chng:Number = .4 + ((mouseY / stage.stageHeight) * .6);
var sX:Tween = new Tween(zac, "scaleX", Regular.easeOut, zac.scaleX, chng, 1, true);
var sY:Tween = new Tween(zac, "scaleY", Regular.easeOut, zac.scaleY, chng, 1, true);
zacTweenY.addEventListener(TweenEvent.MOTION_CHANGE, onMotionChange);
}
// Hit Test
function onMotionChange(e:TweenEvent):void
{
if (dylan.mcDylanWalkPath!=null) {
if (zac.mcZacWalkPath.hitTestObject(dylan.mcDylanWalkPath)){
e.target.stop();
dylan.stop();
}
}
}
As you can see,
Code:
zacTweenY.addEventListener(TweenEvent.MOTION_CHANGE, onMotionChange);
is only referencing the Y tween and not the X tween.
How do I pass the zacTweenX variable into the onMotionChange function?
Thanks for your help
-
ok
I have worked out a way of doing it.
but i'm not to sure if it's the best way to do it:
Code:
zacTweenY.addEventListener(TweenEvent.MOTION_CHANGE, onMotionChange);
zacTweenX.addEventListener(TweenEvent.MOTION_CHANGE, onMotionChange);
This way I'm calling the function twice.
Will this be more processor intensive?
Is there a better way of doing this?
Thanks
-
The built in Tween class is notoriously hard to work with, is pretty limited, and isn't great performance-wise. Most people use any of the several freely available public classes (TweenLite, tweener, GTween, tweensey) or write their own.
I think the Adobe tween is the only one that limits each tween to a single property.
-
Use tweener, Its probably the best, in my personal opinion.
-
ok excellent.
Thanks for your help
-
hi
sorry, but where do you download the tweener class?
I've googled it but can't find a site.
Also, is there a tweener tutorial somewhere?
Thanks
-
i just put "tweener" in google - it's the first result:
http://code.google.com/p/tweener/
you can also try TweenLite:
http://blog.greensock.com/tweenlite/
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
|