views:

316

answers:

2

How would I make a counter using Greensocks TweenMax or TweenLite? Does anyone understand the overwrite manager?

My code will be in AS3. I want it to be timer based, and be capable or resetting it's self and looping. Advice or starter-code would be cool. Also, is it bad to use tweening engines? Let me know.

IDEAS
moving number column "increments by pixels"
0
1
2
3
4
5
6
7
8
9
0

//1
TweenMax.to
(num7, 1, {y:-3911, delay:1, paused:false, useFrames : false, immediateRender : false});
//2
TweenMax.to
(num7, 1, {y:85, delay:2, paused:false, useFrames : false, immediateRender : false});
//3
TweenMax.to
(num7, 1, {y:-3911, delay:3, paused:false, useFrames : false, immediateRender : false});
//4
TweenMax.to
(num7, 1, {y:85, delay:4, paused:false, useFrames : false, immediateRender : false});
//5
TweenMax.to
(num7, 1, {y:-3911, delay:5, paused:false, useFrames : false, immediateRender : false});
//6
TweenMax.to
(num7, 1, {y:85, delay:6, paused:false, useFrames : false, immediateRender : false});
//7
TweenMax.to
(num7, 1, {y:-3911, delay:7, paused:false, useFrames : false, immediateRender : false});
//8
TweenMax.to
(num7, 1, {y:85, delay:8, paused:false, useFrames : false, immediateRender : false});
//9
TweenMax.to
(num7, 1, {y:-3911, delay:9, paused:false, useFrames : false, immediateRender : false});
//10

Appearance "things appear and dissapear, similar to load-sprite-method"
"no example"

My Problems
-infinite looping motions
-global time-scaling and math floor
-garbage build up

+1  A: 

I don't know why you are trying to do a counter using any Tweening engine... instead of a Timer like you have been doing.

To me, it looks like you are just moving num7 from its starting position to y=-3911, then to y=85, in a loop?

What is this counter you are after. Do you want it to do this animation over and over?

sberry2A
The code just demonstrates simple motion. I edited my post to include "overwrite manager" in the question. The counter everyone's helping with is fantastic. I'll probally be asked why I didn't use a tweening engine etc.
VideoDnd
I want the counter to go to a million. Numbers are multiples of 10, two decimals are tenths "10% of wholes", hundredths "10% of tenths".The place values need to loop.
VideoDnd
I think you need to simplify your posts. In general, say something like "I want to animate X, this is what I am doing `code`, how can I improve this or achieve this." Your posts confuse me mostly.
sberry2A
My communication is like this in real life. I haven't found the happy medium yet.
VideoDnd
+1  A: 

It sounds like you have habit of over complicating things. I would probably not use a tweening engine, but might use the Timer class.

I would also separate things out into manageable chunks. At the moment it looks like you have your timing code and you display code all mixed in together. I would create these seperate parts:

  1. CounterTimer - The thing that works out what Count your up to (time-based).
  2. CounterView - The visual graphics of your counter. It's only job is to render what ever number it is TOLD to display. And handle the transitions between states.
  3. CounterController - Sort of a middle-man. Gets the current Count from CounterTimer, and tells CounterView to render that number (frame-based, because you can only render once per frame).

Breaking it down like this means you can concentrate on one component at a time, and test that one part in isolation from the other parts. For example; first you could build the CounterView. This would probably be a MovieClip that holds your graphics on the stage. It might have a method called:

public function displayNumber(numberToDisplay:Number):void

When this method is called, the CounterView will show the graphics for that number, including transitions. To test this component, just call this method from the CounterView parent, with a random number. Once it works you can start working on the CounterTimer.

For the CounterTimer you would probably want it to have a bit more of an API e.g.

public function CounterTimer( startCount:Number ) //This is the constructor.
public function start()
public function reset():void
public function getCount():Number

When CounterTimer is finished, just start on the CounterController to hook them together. The CounterController would need to listen to the enterframe event, and tell CounterView to display CounterTimer's count every frame.

TandemAdam
Thanks so much for explaining, that get closer to to finishing my project.
VideoDnd