Reputation: 43
I have an tween:
TweenLite.to(s, 0.1, {x:100, y:100});
But I want it to stop tweening and go to:
x = 10;
y = 10;
so I use this code: s.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
s.x = 10;
s.y = 10;
}
But the tween keeps tweening and doesn't stop can someone help me with this?
This is the code I simplified but it still doesn't work:
stop();
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.TweenMax;
import com.greensock.TweenLite;
import flash.events.Event;
import com.greensock.TweenLite
stage.addEventListener(MouseEvent.CLICK, rijden); // Add the button click
function rijden(e:MouseEvent):void {
TweenLite.to(auto, 4, {x:666.15, y:375.6});
}
addEventListener(Event.ENTER_FRAME, einde1);
function einde1(e:Event){
if(auto.hitTestObject(stopauto)){
var myTween=TweenLite.to(auto, 4, {x:666.15, y:375.6});
myTween.kill(); //here code for tween killing
trace("works")
//
auto.x = 241;
auto.y = 375;
removeEventListener(Event.ENTER_FRAME, einde1)
}
}
Upvotes: 0
Views: 2923
Reputation: 552
You could assign TweenLite instance to variable like this
var myTween=TweenLite.to(s, 0.1, {x:100, y:100});
and after that kill it with
myTween.kill();
About your comments it should be like this
addEventListener(Event.ENTER_FRAME, einde1);
function einde1(e:Event){
if(auto.hitTestObject(eind)){
//here code for tween killing
//
man.x = 241.3;
man.y = 375;
removeEventListener(Event.ENTER_FRAME, einde1)
}
}
UPD: Problem was in your Timer. You didn't stop it after it should. Also i changed 3 enterFrame listeners to one. Anyway, link to your fixed code sample - https://dl.dropboxusercontent.com/u/39984632/stackoverflowtest.fla
UPD2: To make lives counter you could this. Add
var lives:Number=5;
And change this one:
if(auto.hitTestObject(man) && !autoWasHitByMan){
trace("auto hits man");
autoWasHitByMan=true;
TweenLite.to(man, 4, {x:539.95, y:145, rotation:360});
}
to this
if(auto.hitTestObject(man) && !autoWasHitByMan){
trace("auto hits man");
lives--;
TweenLite.to(man, 4, {x:539.95, y:145, rotation:360});
if(lives==0){
autoWasHitByMan=true;
}
}
Upvotes: 1