The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 4 of 4

Thread: delay a loop?

  1. #1

    delay a loop?

    This adds 3 movieclips to the stage all at once. I would like them to be added one after another - perhaps as soon as the tween finishes, the next one is added. I have tried timers but I ended up with 3 timers for 3 functions. Ideally I will be adding up to 10 and eventually I would like the time between each addition to decrease - you know, like when popcorn starts popping, slowly at first then it really starts popping fast. Sort of like that . Ideas?
    var dArr:Array = new Array();
    dArr.push({ss:.05, xp:30, yp:35, es:.18});
    dArr.push({ss:.05, xp:120, yp:125, es:.28});
    dArr.push({ss:.05, xp:30, yp:100, es:.18});
    function pop4(e:TimerEvent):void {
        for (var j:int = 0; j < 3; j++){
                var dol4:MovieClip = new dollar();
                dol4.scaleX = dol4.scaleY = dArr[j].ss;
                dol4.x = dArr[j].xp;
                dol4.y = dArr[j].yp;
                var sm5 = new Tween(dol4, "scaleX", Elastic.easeOut, .05, dArr[j].es, 1, true);
                var sm6 = new Tween(dol4, "scaleY", Elastic.easeOut, .05, dArr[j].es, 1, true);

  2. #2
    Registered User
    Only idea I've got without Timers and whatnot like you mentioned is using the TweenLite class. Has a built in delay function.

    I usually don't like when someone asks one thing and someone responds with an answer like this, but it really is easier.

  3. #3
    I would say something like this ?
    (copy and paste into a new file to see it working)

    	import flash.display.Sprite;
    	import flash.utils.Timer;
    public class Main extends Sprite
    	private var amount:int = 100; // amount of popcorn
    	private var delay:Number = 1000; // initial delay
    	private var acceleration:Number = .9; // amount delay is reduced by every 'pop()'
    	private var popcorn:Array=new Array(); // array of objects to add to stage, in this case yellow sprites, in your case something different
    	private var myTimer:Timer;
    	public function Main():void
    //Essentially this is adding the items you want on stage to an array - obviously you would add your items to an array totally differently
    	private function createPopcorn():void
    	/*create an array populated with 'popcorn' sprites*/
    		for(var i:int=0; i<amount ;i++)
    			var s:Sprite = new Sprite;;,0,20,20);
    //Self explanatory	
    	private function createTimer():void
    	/*add popcorn to stage*/
    		myTimer = new Timer(delay,1);
    		myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, pop, false, 0, true);
    	private function pop(e:TimerEvent):void
    	/*Add popcorn to stage. Restart timer if more popcorn*/
    //I think this is where you would run your pop4() code
    		//add popcorn to stage
    		popcorn.shift();// you will still need this to shorten your array
    		//check if there is more popcorn and restart timer if there is
    		if(popcorn.length>0) // and you will need this as well.
    			delay *= acceleration;
    			myTimer.delay = delay; 
    EDIT - attached as a standalone .fla file
    Attached Files Attached Files
    Last edited by Shaedo; January 12th, 2010 at 11:39 AM.

  4. #4
    too cool. I owe you one. Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012