PDA

View Full Version : trying to make a 3-dot waiting animation


he11fire
12-13-2011, 09:18 PM
Hello !
I am trying to make a 3-dot waiting animation using action script.
I want it to go until three dots "..." and than start over again until I manually stop it later in my program.
I tried many stuff including arrays and surrendered.
Please help me !

-:)lauri
12-13-2011, 09:55 PM
Here could be something to start of:

var dotAnimTextField:TextField = new TextField();
var timer:Timer = new Timer(500);
var dotAnimOnOff:Boolean = true;
var dots:String = "";
addChild(dotAnimTextField);

timer.addEventListener(TimerEvent.TIMER, playDotAnim);
timer.start();

function playDotAnim(e:TimerEvent):void{
if(dotAnimOnOff) {
if(!dotAnimTextField.visible) dotAnimTextField.visible = true;
if(dots.length < 3) dots += ".";
else dots = "";
dotAnimTextField.text = dots;
}else{
dotAnimTextField.visible = false;
timer.removeEventListener(TimerEvent.TIMER, playDotAnim);
}
}


To stop this manually set, "dotAnimOnOff" to false;

[afz]snickelfitz
12-13-2011, 10:48 PM
This is probably overly complex, but it works.
Uses greensock TweenMax for the animation.
You need a MovieClip that contains a 10px circle at 0,0, in the library, class name Dot
The following script on frame1.
you hide the dots by calling the hideDots function.

import flash.display.Sprite;
import com.greensock.*;

var dotArray:Array = new Array();
var dots:Sprite = new Sprite();

var pad:Number = 2;
var dotX:Number = 0;

function makeDots():void
{
for (var i:int = 0; i < 3; i++)
{
var dot:Dot = new Dot();
dot.x = dotX;
dots.addChild(dot);
dotArray.push(dot);
dotX = dots.width + pad;
}

TweenMax.to(dots, 0, {autoAlpha:0, x:stage.stageWidth * .5, y:stage.stageHeight});
addChild(dots);

showDots();
}

function showDots():void
{
TweenMax.to(dots, .5, {autoAlpha:1, x:stage.stageWidth * .5, y:stage.stageHeight * .5, onComplete:tweenDots});
}

function tweenDots():void
{
TweenMax.allFrom(dotArray, .2, {alpha:0}, .1, tweenDots);
}

function hideDots():void
{
TweenMax.killAll(false, true, true);
TweenMax.to(dots, .5, {autoAlpha:0, x:stage.stageWidth * .5, y:stage.stageHeight});
}

makeDots();

he11fire
12-14-2011, 12:32 PM
Thanks a lot ..
That's a simple and efficient way.

he11fire
12-14-2011, 12:34 PM
That may be a good way but I'm still not into this kind of stuff.
Gonna learn some engines soon including GreenSock.