Jump to content
GreenSock

kwontae

how to get the TweenLite to be reborn

Recommended Posts

Hi Greensock

 

I'm using the TweenLite on my timeline. I killed the TweenLite with "TweenLite.killTweensOf" but I'd like to remove the "TweenLite.killTweenOf" to return to the original TweenLite. 

 

 I'd like to insert some code to remove "TweenLite.killTweenOf" after the code below "if (infi01.currentLabel == "play")"

 

I want my Tween to be reborn. If you can help me again, it would be much appreciated. 

addEventListener(Event.ENTER_FRAME, infiBoxHandler_1);
					function infiBoxHandler_1(event:Event):void
					{

						TweenLite.killTweensOf(event.currentTarget);
						

						var i:int = 0;

						while (i < checks.length )
						{
							i++;
							if (btnspeak.currentLabel == btnENums[i] && checks[i].selected == false)
							{
								btnspeak.gotoAndPlay("btnS01");

							}

						}


						if (infi01.currentLabel == "play")
						{

							removeEventListener(Event.ENTER_FRAME, infiBoxHandler_1);
							
							
							
						}

Link to comment
Share on other sites

instead of killing the tweens, you could use TweenMax.getTweensOf()

http://api.greensock.com/js/com/greensock/TweenMax.html#getTweensOf()

 

That will give you an array of tweens that you can loop through and then call pause() on each tween.

 

 

When you want those tweens to start again, loop through that area again and tell them each to pause()

 

If you know only 1 tween will control an object at a given time you could do

 

 

 

TweenMax.getTweensOf(event.currentTarget)[0].pause();
 

I haven't tested that but I'm pretty sure it will work

Link to comment
Share on other sites

Thanks for your quick reply.

 

I tried your way, but some errors occurred. I don't know what's wrong. 

 

Here is my code with the "TweenMax.getTweensOf()". I'm not using class as I'm new to AS3.

 

 


 
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_1);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_2);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_3);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_4);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_5);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_6);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_7);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_8);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_9);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_10);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_11);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_12);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_13);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_14);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_15);
addEventListener(Event.ENTER_FRAME, btn_EnterFrameHandler_16);
 
 
function btn_EnterFrameHandler_1(event:Event):void
{
    if (btnspeak.currentLabel == "btnS01+1")
    {
 
        btn01.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:0});
    }
}
 
function btn_EnterFrameHandler_2(event:Event):void
{
    if (btnspeak.currentLabel == "btnS02+1")
    {
 
        btn02.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:0});
 
    }
}
 
function btn_EnterFrameHandler_3(event:Event):void
{
    if (btnspeak.currentLabel == "btnS03+1")
    {
 
        btn03.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:0});
 
    }
}
 
function btn_EnterFrameHandler_4(event:Event):void
{
    if (btnspeak.currentLabel == "btnS04+1")
    {
 
        btn04.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:0});
 
    }
}
 
function btn_EnterFrameHandler_5(event:Event):void
{
    if (btnspeak.currentLabel == "btnS05+1")
    {
 
        btn05.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:0});
 
    }
}
 
function btn_EnterFrameHandler_6(event:Event):void
{
    if (btnspeak.currentLabel == "btnS06+1")
    {
 
        btn06.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-100});
 
    }
}
 
function btn_EnterFrameHandler_7(event:Event):void
{
    if (btnspeak.currentLabel == "btnS07+1")
    {
 
        btn07.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-200});
 
    }
}
 
function btn_EnterFrameHandler_8(event:Event):void
{
    if (btnspeak.currentLabel == "btnS08+1")
    {
 
        btn08.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-300});
 
    }
}
 
function btn_EnterFrameHandler_9(event:Event):void
{
    if (btnspeak.currentLabel == "btnS09+1")
    {
 
        btn09.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-400});
 
    }
}
 
function btn_EnterFrameHandler_10(event:Event):void
{
    if (btnspeak.currentLabel == "btnS10+1")
    {
 
        btn10.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-500});
 
 
    }
}
 
function btn_EnterFrameHandler_11(event:Event):void
{
    if (btnspeak.currentLabel == "btnS11+1")
    {
 
        btn11.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-600});
 
    }
}
 
function btn_EnterFrameHandler_12(event:Event):void
{
    if (btnspeak.currentLabel == "btnS12+1")
    {
 
        btn12.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-700});
 
    }
}
 
function btn_EnterFrameHandler_13(event:Event):void
{
    if (btnspeak.currentLabel == "btnS13+1")
    {
 
        btn13.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-785});
 
 
    }
}
 
function btn_EnterFrameHandler_14(event:Event):void
{
    if (btnspeak.currentLabel == "btnS14+1")
    {
 
        btn14.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-785});
 
    }
}
function btn_EnterFrameHandler_15(event:Event):void
{
    if (btnspeak.currentLabel == "btnS15+1")
    {
        btn15.alpha = 0;
        TweenLite.to(MovieClip(parent).vertical, 0.5, {x:0, y:-785});
 
    }
}
 
function btn_EnterFrameHandler_16(event:Event):void
{
    if (btnspeak.currentLabel == "btnE15+1")
    {
 
        MovieClip(parent).control.playandstop.gotoAndStop(1);
        btnspeak.gotoAndStop("btnS01-1");
 
    }
}



 

 

 

infi07.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler_7);
function mouseDownHandler_7(event:MouseEvent):void
{
    stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler_7);
    mouseDownX = stage.mouseX;
    mouseDownY = stage.mouseY;
    clickedButton = event.target as DisplayObject;
 
    isClick = true;
    TweenLite.delayedCall(clickTime, notClick_7);
}
 
function notClick_7():void
{
    isClick = false;
}
 
function mouseUpHandler_7(event:MouseEvent):void
{
    stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler_7);
    if (isClick && Math.abs(mouseDownX - stage.mouseX) < 22 && Math.abs(mouseDownY - stage.mouseY) < 22)
    {
        if (infi07.currentLabel == "play")
        {
 
            if (check07.selected == false)
            {
                for (i = 0; i < checks.length; i++)
                {
                    checks.selected = false;
                }
            }
 
            for (i = 0; i < btns.length; i++)
            {
                if (i == 6)
                {
                    continue;
                }
                btns.alpha = 1;
            }
            btn07.alpha = 0;
 
 
            btnspeak.alpha = 0;
            MovieClip(parent).control.playandstop.gotoAndStop(1);
 
            btnspeak.gotoAndPlay("btnS07");
            infi07.gotoAndStop(2);
            for (var i:int = 0; i < infis.length; i++)
            {
                if (i == 6)
                {
                    continue;
                }
                infis.gotoAndStop(1);
            }
 
        }
        else if (infi07.currentLabel == "pause")
        {
            btnspeak.stop();
            infi07.gotoAndStop(1);
 
        }
        addEventListener(Event.ENTER_FRAME, fl_InfiFrameHandler_7);
    }
    function fl_InfiFrameHandler_7(event:Event):void
    {
        if (btnspeak.currentLabel == "btnE07" && check07.selected == false)
        {
            btnspeak.gotoAndPlay("btnS07");
        }
        if (infi07.currentLabel == "play")
        {
 
            removeEventListener(Event.ENTER_FRAME, fl_InfiFrameHandler_7);
        }
        else if (btnspeak.currentLabel == "btnE07" && check07.selected == true)
        {
            removeEventListener(Event.ENTER_FRAME, fl_InfiFrameHandler_7);
            addEventListener(Event.ENTER_FRAME, infiBoxHandler_7);
            function infiBoxHandler_7(event:Event):void
            {
 
                TweenMax.getTweensOf(event.currentTarget);
 
                var i:int = 6;
 
                while (i < checks.length )
                {
                    i++;
                    if (btnspeak.currentLabel == btnENums && checks.selected == false)
                    {
                        btnspeak.gotoAndPlay("btnS07");
 
                    }
 
                }
 
 
                if (infi07.currentLabel == "play")
                {
 
                    removeEventListener(Event.ENTER_FRAME, infiBoxHandler_7);
                    
                    TweenMax.getTweensOf(event.currentTarget)[0].pause();
                    
                }
 
 
 
 
            }
 
        }
 
    }
    TweenLite.killDelayedCallsTo(notClick_7);
}
Link to comment
Share on other sites

Sorry, but its going to be near impossible for me to try to troubleshoot that amount of code or try to figure out how it is supposed to be working just by reading it. 

 

It really would be best if you could try to isolate the functionality you want in a very simple file with only 1 or 2 buttons or items that are being tweened.

 

It could be something as simple as you saying "here is a file with 3 objects being tweened, how do i make them stop when you roll over them?". Once you understand a basic implementation you will have better luck integrating into your current file.

 

The only thing I can suggest now is that the code you have this floating around

 

 

TweenMax.getTweensOf(event.currentTarget);
 
which doesn't really do anything on its own, other than give you an Array of tweens that affect event.currentTarget. 
 
Here is a basic example of what I was trying to explain earlier:
 
import com.greensock.*;




TweenLite.to(mc, 8, {x:400});


mc.addEventListener(MouseEvent.ROLL_OVER, over);
mc.addEventListener(MouseEvent.ROLL_OUT, out);


function over(e:MouseEvent):void{
    TweenMax.getTweensOf(e.currentTarget)[0].pause();
    }




function out(e:MouseEvent):void{
    TweenMax.getTweensOf(e.currentTarget)[0].play();
    }
 

This gives you a generic means of playing and pausing the tween of the item you are rolling over. 

Link to comment
Share on other sites

And why are you creating a bunch of ENTER_FRAME handlers that are conditionally spawning new tweens constantly? That looks extremely wasteful and error-prone to me. If your swf is running at 60fps, you're literally spawning at least 60 nearly identical tweens every second. 

 

I don't mean this as an insult in any way, but it looks to me like your project has major architectural problems that would take a significant amount of time to explain and solve. 

 

If you're in a rush to get this done, I suspect you might be best served by hiring a professional developer who has some experience with this type of thing. Otherwise, if you're just trying to polish up your own skills, that's great - I'd recommend going through some ActionScript books or online courses that cover more general things. We try to stay very focused in these forums on GreenSock-related questions rather than general ActionScript troubleshooting. 

 

There's no shame in having some architectural problems either - we've ALL had that. Everybody is learning (or should be). We just can't spend a lot of time here in these forums on that sort of thing, that's all (unless it's directly related to GreenSock tools, but it looks to me like the problems you're facing here are much broader than that). 

 

Good luck with your project. 

Link to comment
Share on other sites

Thank you for your consideration. 

I'm worried about my project. Unfortunately I don't have enough money to hire a professional. But I guess I would work it out if I get a lot of patience with learning AS3 in general. It's a wonder for me to see some problem being solved. AS3 is totally new field to me. I've never written any code before. 

 

Thank you again for letting me know the architectural problem with my project. Your advice would be a big help. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×