Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Call Function Sequence Randomly

Posted on 2008-09-29
1
Medium Priority
?
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

722 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