Solved

Call Function Sequence Randomly

Posted on 2008-09-29
1
275 Views
Last Modified: 2013-11-11
My code is below. I'm simply trying to make the functions random, instead of sequential, Please help, as this is urgent!


/* Start from panel 1 */
_root.show1();
 
var fnArray = [show1, show2, show3, show4];
var counter = 0;
var intervalId;
function callfunctions() {
        fnArray[counter]();
        counter = counter+1<fnArray.length ? counter+1 : 0;
 
}
 
 
function startTimer(num) {
        clearInterval(intervalId); /* Cleared interval, because clicking each button would offset the timer */
        counter = num; /* Removed "-1" because of odd jump */
        intervalId = setInterval(callfunctions, 5500);
}
 
/* Also removed stopTimer(); because we're calling startTimer(); in each button */
 
_root.startTimer(1); /* Starts the timer for panel 1 */

Open in new window

0
Comment
Question by:webrhp
1 Comment
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 22597264
below is the updated code:

var fnArray = [show1, show2, show3, show4];
var counter = 0;
var intervalId;
function callfunctions() {
 
	var rnd = random(fnArray.length);
	if (rnd == counter) {
		callfunctions();
		return;
	}
	fnArray[rnd]();
	counter = rnd;
}
function startTimer() {
	clearInterval(intervalId);
	intervalId = setInterval(callfunctions, 5500);
}
callfunctions();
startTimer();
 
 
function show1() {
	trace('show1');
}
 
function show2() {
	trace('show2');
}
 
function show3() {
	trace('show3');
}
 
function show4() {
	trace('show4');
}

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Flash doesn't load in Iphone and Ipad 22 492
flash cs6 4 347
Flash being Disabled - help! 20 343
Text Transformation using ActionScript 3 5 153
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question