Jump to content
Search Community

need basic help with getActive() [SOLVED]

-Dexter- test
Moderator Tag

Recommended Posts

Hi could anyone shed some light on how to use the "getActive()" method? I'm trying to do something like this (got it from another topic) but it doesn't return anything..

		var a:Array = myTimeline.getActive();
	for (var i:Number = 0; i <= a.length; i++) {
   	trace(a[i].target + " is tweening");
	}

 

Saying that I'm new to TweenLite/Max would be banal, so I'll add that I'm new to Flash, AS and programming as well :lol:

 

Thanks for any input :)

Link to comment
Share on other sites

Sorry, I should have explained that first. Ok here goes. I have a row of thumbnail images which use the ENTER_FRAME event to move to the left or to the right depending on mouseX. I wanted to stop this movement when the beginning/end is reached using tweens:

var myTimeline:TimelineMax = new TimelineMax();
myTimeline.append(new TweenMax(thumbnailBar, 0.2, {x:0, ease:Quad.easeOut, paused:true, overwrite:0}));
myTimeline.addLabel("smoothLeftScroll", 0);
myTimeline.append(new TweenMax(thumbnailBar, 0.2, {x:(thumbnailArea.x - thumbnailBar.width + thumbnailArea.width), ease:Quad.easeOut, paused:true, overwrite:0}));
myTimeline.addLabel("smoothRightScroll", 0.2);

function thumbGallery(e:Event):void
{
/*
some code here
*/
if (thumbnailBar.x > 5.7 * prevDiff && prevDiff < 0) // beginning reached. prevDiff < 0 means thumbnailBar moves to the left.
{
	myTimeline.gotoAndStop("smoothLeftScroll");
	myTimeline.tweenTo("smoothRightScroll");
}
else if (thumbnailArea.x - thumbnailBar.width + thumbnailArea.width - thumbnailBar.x > -5.7 * prevDiff && prevDiff > 0) // end reached
{
	myTimeline.gotoAndPlay("smoothRightScroll");
}
else
{
	thumbnailBar.x -= prevDiff;
}



   var a:Array = myTimeline.getActive();
   for (var i:Number = 0; i < a.length; i++) {
   	trace(a[i].target + " is tweening");
   }
}

I'm guessing this does not run properly because "myTimeline" is called multiple times. "TweenMax(thumbnailBar, 0.2, {x:0, ease:Quad.easeOut, paused:true, overwrite:0})" doesn't seem to help either. So my idea was to use "getActive()" and call "myTimeline" only when there are no tweens running already.

Link to comment
Share on other sites

I noticed a few things:

 

1) There's really no reason to use overwrite:0 with TweenMax (at least I can't think of one). It uses AUTO mode by default which intelligently figures out when to kick in (only when you're doing two tweens of the same object at the same time)

 

2) You paused your tweens that were inserted into your timeline. That paused state is honored even if you play the tween's parent timeline. Basically, think of TimelineLite/Maxes as the clock by which their child tweens rely for timing - if you pause/stop the timeline, that stops the clock which in turn appears to pause the child tweens (even though their "paused" property technically hasn't been set to true). This may seem slightly odd at first, but trust me - it is the most straightforward way to do it and engineering it a different way would cause much more significant problems. In any case, the point is that you should NOT pause your tweens. Just pause the TimelineMax instance instead.

Link to comment
Share on other sites

I'm sorry about the nonsense in my previous post. I was experimenting with tweens and then suddenly decided to try TimelineMax and ended up with some mixture of different commands. The following code shows what I'm after (I hope).

import com.greensock.*;
import com.greensock.easing.*;

var square:MovieClip = new MovieClip();
addChild(square);
square.graphics.lineStyle(3,0x00ff00);
square.graphics.beginFill(0x0000FF);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();
square.x = stage.stageWidth/2-square.width/2;
square.y = stage.stageHeight/2-square.height/2;
square.addEventListener( Event.ENTER_FRAME, movesquare );
var tweenLeft:TweenMax = new TweenMax(square, 2, {x:0, paused:true});

function movesquare(e:Event):void
{
if (mouseX < 20)
	tweenLeft.play();
else
{
	tweenLeft.kill();
	square.x = mouseX;
}
}

 

Basically I want to use a tween when mouseX becomes less than 20 pixels from the left edge of the stage. I also want the tween to do three things:

1. play and stop once when mouseX < 20

2. stop playing (if currently tweening) and follow the mouse cursor if mouseX becomes >= 20.

3. play again when mouseX < 20

 

The above code will play the tween just once (the first time mouseX becomes less than 20). I also tried invalidate() instead of kill() and restart() instead of play() but it still doesn't work the way I want it. Even if it did is it a good idea to call "tweenLeft.kill();" 24 times per second? Should I try something that runs just once when I need it instead?

Link to comment
Share on other sites

I would do something like this:

 

square.addEventListener(Event.ENTER_FRAME, movesquare);
var tweenLeft:TweenMax;

function movesquare(e:Event):void {
  if (mouseX        if (tweenLeft == null) {
          tweenLeft = new TweenMax(square, 2, {x:0});
       }
  } else {
      if (tweenLeft != null) {
	   tweenLeft.kill();
	   tweenLeft = null;
      }
      square.x = mouseX;
  }
}

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...