package
{
import com.flashdynamix.motion.TweensyGroup;
import com.flashdynamix.motion.TweensyTimeline;
import fl.motion.easing.Cubic;
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
[SWF(frameRate="31",backgroundColor="0x000000")]
public class TweensyGroups extends Sprite
{
private const AMOUNT:int = 10;
private var _s:Shape;
private var _shapes:Vector.<Shape>;
private var _timeline:TweensyTimeline;
private var _group:TweensyGroup;
private var _isPaused:Boolean = false;
public function TweensyGroups()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE,init);
}
private function init(e:Event):void
{
stage.removeEventListener(Event.RESIZE,init);
_group = new TweensyGroup(false,true);
_shapes = new Vector.<Shape>();
var s:Shape;
var t:TweensyTimeline;
for(var i:int=0;i<AMOUNT;++i){
s = new Shape();
s.graphics.beginFill(Math.random() * Math.random() * 0xFFFFFF);
s.graphics.drawRoundRectComplex(-20, -20, 40, 40, 8, 8, 8, 8);
s.x = Math.random()*stage.stageWidth;
s.y = Math.random()*stage.stageHeight;
s.graphics.endFill();
_shapes[_shapes.length] = s;
addChild(s);
t = _group.to(s,{x:Math.random()*stage.stageWidth, y:Math.random()*stage.stageHeight},3.0);
t.repeatType = TweensyTimeline.YOYO;
t.delayStart = Math.random()*1.0;
t.ease = fl.motion.easing.Cubic.easeInOut;
}
}
}
}
With object pooling enabled I set lazymode to false so you ought to handle your timelines' lives.
As you can see i have only one tweensygroup and many timelines each with its own properties.
A good way to handle timelines could be put each timeline in a dictionary using the tweened object as a key (something like mydict[s] = t in the previous example). In this way you can check the dictionary before instantiate a new timeline for an already tweening object (which can generate an unpredictable error, remember you're in lazymode=false) and choose whether to use an updateTo command or a simple to\fromTo.
i hope it helps.
bye
Piergiorgio Niero
TheFlashMind AUG - Italy