How to add delay in for loop

Explorer ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

Hi,

I want to delay in for loop. How can i do? 

I will be grateful if you could help me.

 

Good work.

Views

121

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Nov 02, 2020 Nov 02, 2020
Code-driven animation is based on timers. Your animation setup code will set up all the required variables, then call a function that performs the first step of the animation. This function will then perform the first step of the animation, and if there are more steps, use a setTimeout() call to schedule itself to run again after the desired delay. This will repeat until there are no more steps.

Likes

Translate

Translate
Adobe Community Professional ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

You DON'T put a delay in a for loop. What are you actually trying to do that you think this is a good idea?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.utils.setTimeout;

var bh:Symbol1 = new Symbol1();
var bhs:Symbol2 = new Symbol2();
var quest:Array = [1,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1,0,1];
var len:uint = quest.length;

 

function bhchild(){
bh = new Symbol1();
addChild(bh);
bh.x = 415.7;
bh.y = 149.6;
}

function bhschild(){
bhs = new Symbol2();
addChild(bhs);
bhs.x = 519.25;
bhs.y = 149.6;
}

for(var i:uint = 0; i < len; i++)
{

if(quest[i] == 0)
{
bhchild();
//setInterval(bhchild, 1000);
}
else
{
//setInterval(bhschild, 1205);
//setTimeout(bhschild, 100);

bhschild();
}
}

stop();

 

According to the example above, I want the for loop to play the MovieClip type symbols 20 times. When I check with Debug my loop runs as many times as I want. However, when I run the animation, I cannot play the animation in the order the code is running. This animation is only once work.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 01, 2020 Nov 01, 2020

Copy link to clipboard

Copied

I want to create an animation that repeats according to the number of elements in the array, and add the symbol according to the element value of the array being 1 or 0. My goal is to create an animation by bringing up the two different MovieClip I created based on the number of values in the quest variable.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

LATEST

Code-driven animation is based on timers. Your animation setup code will set up all the required variables, then call a function that performs the first step of the animation. This function will then perform the first step of the animation, and if there are more steps, use a setTimeout() call to schedule itself to run again after the desired delay. This will repeat until there are no more steps.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines