Jump to content
Search Community

TimelineMax and Removing a tween

junky test
Moderator Tag

Recommended Posts

I'm using the latest AS2 TimelineMax and want to remove one of the tweens from the timeline when a button is rolled over, but I can't seem to get timeline.remove(myTween) to work. Here's the basics of my code.

 

var timeline:TimelineMax

timeline = new TimelineMax({repeat:23,yoyo:false});

 

for(var i=0; i<2; i++)

{

sections[num]["word"+i+"_mc"].gotoAndStop(1);

var targ:MovieClip=sectionHolder_mc[sections[currentSection]]["word"+i+"_mc"];

targ.num = i

targ.stop();

targ.onRollOver=function()

{

wordOver(this);

}

 

timeline.insert( TweenMax.to(targ, .5, {glowFilter:{color:0xFFFFFF, alpha:glowAlphas[currentSection], blurX:10, blurY:10}}) );

timeline.insert( TweenMax.to(targ, .5, {glowFilter:{color:0xFFFFFF, alpha:0, blurX:10, blurY:10, remove:true}, delay:.5}) );

}

 

 

 

//BUTTON ACTION HERE

function wordOver(targ:MovieClip):Void

{

if(targ._currentframe==1)

{

targ.play();

//CAN'T Figure out what needs to go here to remove a tween in the timeline.

}

}

Link to comment
Share on other sites

If you want to remove a particular tween, you need to store a reference of it somewhere so that you can feed it to the remove() method. Or if you want to kill all the tweens of a particular object, just use the TweenLite.killTweensOf(myObject) method. I suspect that's what you're after, right?

Link to comment
Share on other sites

  • 1 year later...

First of all, hello!

 

I have a similar problem, I am trying to update some variables(skyXto & fieldXto) in some tweens inserted in a timeline. And in order to achieve this,when I resize the stage, I try:

skyXto = (sky_mc._width - Stage.width);
fieldXto = (field_mc._width - Stage.width);

parallaxTween.remove(skyTween);
parallaxTween.remove(fieldTween);

delete skyTween;
delete fieldTween;

var skyTween:TweenMax = new TweenMax(sky_mc,11,{scrollRect:{x:skyXto},ease:Linear.easeNone});
var fieldTween:TweenMax = new TweenMax(field_mc,11,{scrollRect:{x:fieldXto},ease:Linear.easeNone});

parallaxTween.insert(skyTween);
parallaxTween.insert(fieldTween);

 

Does anyone have any idea why this doesn't work?

Link to comment
Share on other sites

assuming that code is part of a RESIZE event handler function, it could be a scope issue.

 

declaring var:skyTween = new TweenMax...

 

inside a function means that reference to skyTween is only valid inside that function when that function runs.

 

 

can you trace(skyTween) before you remove it or attempt to delete it? what do you get?

Link to comment
Share on other sites

You are right, that wasn't what I wanted(scope wise), thank you.

The problem still exists. After I remove the tweens from the timeline(i'm not really sure if timeline.remove(tween) really works though, I don't know how to test that) and insert the new ones, my traces of the timeline progress indicate that it changes, but visually nothing happens. It's like the insert doesn't work any more.

 

I have uploaded the .fla I'm working on here:https://www.wetransfer.com/dl/2rNIe2Qx/80b0b641f4bf28c27c8b908013f602b0caa72e8a4590efe0530628bb9905edc2e355050f12de421

Maybe you have the time to look at it.

 

Also, how could one make a listener for timeline.currentProgress?

Link to comment
Share on other sites

to test if remove works do this:

 

	trace("pTween children before remove()" + parallaxTween.getChildren());

parallaxTween.remove(skyTween);
parallaxTween.remove(fieldTween);

trace("pTween children after remove() " + parallaxTween.getChildren());

 

it appears to be working fine.

 

--------

 

I don't know exactly what you mean by an eventListener for currentProgress, but you can add an onUpdate to the TimelineMax that could test the value of currentProgress.

 

--------

 

I regret that I don't have the time to troubleshoot and test your file extensively.

Link to comment
Share on other sites

I finally made it work :)

 

It had nothing to do with TimelineMax after all.

 

When I was doing my calculations:

skyXto = (sky_mc._width - Stage.width);
fieldXto = (field_mc._width - Stage.width);

both the widths of the mc's i was trying to move around were the same as the stage width, that's why it wasn't moving.

It was all because of scrollRect, that is somehow buggy because I needed to null it a couple of times until sky_mc._width was the original one, not the one of the scrollRect :)

 

Sorry for all the trouble!

At least now I know how to remove and see what tweens the timeline has :P

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.
×
×
  • Create New...