[Tweener] Tighten the Loop Part II
Gerry Creighton
gerry at thespikeranch.com
Tue Oct 28 18:44:57 PDT 2008
Matt,
I wrote this tonight that cleans things up, it might do what you want
in a different way.
I made this as file the document class for an fla. This sample can be
see here:
www.thespikeranch.com/test/moveboxes/
Hope that helps.
-Gerry
:::::::::::::::::::::::: START ::::::::::::::::::::::
package {
import flash.display.Sprite;
import flash.events.Event;
import caurina.transitions.Tweener;
public class BoxMove extends Sprite {
private var box:Sprite;
private var bw:Number;
private var bh:Number;
private var startx:Number;
private var endx:Number;
private var boxes:Array;
private var cols:Array;
private var tempArray:Array;
private var cur:Number;
public function BoxMove():void{
//
bw = 400;
bh = 200;
startx = -400;
endx = 400;
boxes = new Array();
tempArray = new Array();
cols = [0x000000,0x990000,0xFFCC00];
cur = 0;
init();
}
private function init():void {
trace("init");
for(var i:Number = 0; i< cols.length; i++){
trace("i --> "+i);
box = new Sprite();
box.graphics.beginFill(cols[i]);
box.graphics.drawRect(0,0,bw,bh);
box.graphics.endFill();
addChild(box);
box.addEventListener(Event.ENTER_FRAME,resetBox);
boxes.push(box);
//set boxes to neg position
boxes[i].x = startx;
}
//start animation
moveIt(boxes[cur]);
}
private function moveIt(_mc:Sprite):void{
trace("moveIt");
//animate
Tweener.addTween(_mc,{x:0,time:
1,transition:"easeinoutexpo",onComplete:nxtBox,onCompleteParams:[_mc]});
}
private function nxtBox(_mc:Sprite):void {
trace("reSet, cur --> "+cur);
//increase cur value
cur++;
if(cur >= boxes.length) cur = 0;
Tweener.addTween(_mc,{x:400,time:1,delay:
5,transition:"easeinoutexpo",onComplete:moveIt,onCompleteParams:
[boxes[cur]]});
}
private function resetBox(e:Event):void {
var clip:Sprite = Sprite(e.target);
if(clip.x >= endx) clip.x = startx;
}
}
}
:::::::::::::::::::::::: END :::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The Spike Ranch
Web Design and Development
http://www.thespikeranch.com
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
On Oct 28, 2008, at 5:58 PM, Matt Tedeschi wrote:
> Going a bit crazy here trying to figure out how to make a loop where
> movie
> clips enter from stage left -- sit on stage for some time -- and
> then exit
> stage right (so the clips need to be reset to the negative stage left
> x)... I have the loop working, except for that the gap between the
> last
> clip and the first clip is too wide.
> If you care to take a look you can see it working here:
> http://www.qwlproductions.com/tweener/test.swf
>
> I just need the transitions to be the same... from the red box to the
> black box though, there is a delay.
>
> I've just not been able to figure out what's wrong -- changing the
> delay
> or time on any of the settings hasn't proved fruitful. The only thing
> that did seem to work was removing the -- time: .5 -- setting on the
> second 'box3' tween, but then that takes away the smooth transition.
>
> Can you help me see what's wrong?? Thanks in advance.
>
> import caurina.transitions.*;
>
> function slideBoxes():void {
>
> var boxArray:Array = new Array(box1, box2, box3);
>
> for (var i:uint = 0; i < boxArray.length; i++) {
> var boxLocation = boxArray[i];
> boxLocation.x = -400;
> boxLocation.y = 0;
> boxLocation.alpha = 1;
> }
>
> Tweener.addTween(box1, { x: 0, time: .5, delay: 0, alpha: 1,
> transition:
> "easeIn" } );
> Tweener.addTween(box1, { x: 400, time: .5, delay: 5, alpha: 0,
> transition: "easeOut" } );
>
> Tweener.addTween(box2, { x: 0, time: .5, delay: 5, alpha: 1,
> transition:
> "easeIn" } );
> Tweener.addTween(box2, { x: 400, time: .5, delay: 10, alpha: 0,
> transition: "easeOut" } );
>
> Tweener.addTween(box3, { x: 0, time: .5, delay: 10, alpha: 1,
> transition:
> "easeIn" } );
> Tweener.addTween(box3, { x: 400, time: .5, delay: 15, alpha: 0,
> transition: "easeOut", onComplete:slideBoxes } );
>
> }
>
> slideBoxes();
>
> _______________________________________________
> Tweener mailing list
> Tweener at lists.caurinauebi.com
> http://lists.caurinauebi.com/listinfo.cgi/tweener-caurinauebi.com
More information about the Tweener
mailing list