9 Replies Latest reply on Dec 26, 2010 11:41 AM by kglad

# How to create a Random Timeline with checks?

I have a simple multiple question quiz with 100 questions.

I want the questions to be randomly asked, without repea

ting a questions as the end works on a scoring system out of the 100 so it needs to ask

all the questions.

Question one starts on frame 5 of the timeline and the last question is on frame 105.

Can someone please assist on how to write this script with the checks?

• ###### 1. Re: How to create a Random Timeline with checks?

// begin code

var frameA:Array = [];

for(var i:Number=5;i<=105;i++){

frameA.push(i);

}

shuffle(frameA);

function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
return a;
}

// end code

// now the first question is on frame frameA[0], the next on frameA[1], etc

• ###### 2. Re: How to create a Random Timeline with checks?

Thanks for your speedy response. I have currently a script on the buttons which are the multiple choice answers of on release goto the next frame and the correct answer has a score++. Could you please explain how to incorpirate your script into this and if I could ask if you could explain the workings of your script so I could understand it better for future use.

Thanks

• ###### 3. Re: How to create a Random Timeline with checks?

// begin code

// the for-loop populates frameA with numbers 5,6,...,105

var frameA:Array = [];

for(var i:Number=5;i<=105;i++){

frameA.push(i);

}

// the shuffle() function randomizes the contents of frameA

shuffle(frameA);

function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
return a;
}

// end code

// now the first question is on frame frameA[0], the next on frameA[1], etc

• ###### 4. Re: How to create a Random Timeline with checks?

http://rapidshare.com/files/439292244/Learners_Shuffle.fla

Thanks for advice. It seems to work with the random effect however has a few glitches.

I am attaching a link to a shortened version .fla file of what I am trying to complete. If you could please download then you will see the random works however repeats same frames a few times and does not go to the last frame to give you the final score.

If you could please assist with this?

• ###### 5. Re: How to create a Random Timeline with checks?

the only free help i offer is via the adobe forums.  in particular, i don't download and correct files unless i'm hired.

if you can explain the issue here, i'll continue to help.

• ###### 6. Re: How to create a Random Timeline with checks?

I do apologise, it was not my intent. I thought that if you s

aw the file you would understand the problem. I love trying to sort

things out myself and am on the brink of a breakthrough however??

The problem is and I will explain with the short version I am trying out first.

Frame 1 is the welcome screen and has a start button to start the quiz.

Frame 2 the quiz starts and is a multiple answer quiz with 3 answer option only one being correct with the score++ I have on the actions tab the script you sent me of:

// begin code

// the for-loop populates frameA with numbers 5,6,...,105

var frameA:Array = [];

for(var i:Number=5;i<=105;i++){

frameA.push(i);

}

// the shuffle() function randomizes the contents of frameA

shuffle(frameA);

function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
return a;
}

// end code

Each answer is a button and has the gotoAndStop(frameA[0]); script on them:

The next frame is the next question and has the 3 buttons as well with the following script: gotoAndStop(frameA[1]);

and then so on till frame 6 with the following script on the 3 buttons: gotoAndStop(frameA[5]);

It does randomize the questions but seems to repeat questions and does not end up in frame 7 when all questions completed, I assumed with the check it would automatically go to the next frame but am now thinking I need a script to tell it that on completion it needs to go to frame 7.

Frame 7 basically does the math of the score++ and gives a total.

I do hope you can assit and once again do apologies.

Thanks.

• ###### 7. Re: How to create a Random Timeline with checks?

should be using something  like:

// begin code

// the for-loop populates frameA with numbers 5,6,...,105

var frameA:Array = [];

for(var i:Number=5;i<=105;i++){

frameA.push(i);

}

// the shuffle() function randomizes the contents of frameA

shuffle(frameA);

function shuffle(a:Array):Array {
var len:Number = a.length-1;
for (var ivar:Number = len; ivar>=0; ivar--) {
var p:Number = Math.floor(Math.random()*(ivar+1));
var t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
return a;
}

var frameIndex:Number=-1;

// end code

then each button in every frame should use:

frameIndex++;
if(frameIndex<frameA.length){
gotoAndStop(frameA[frameIndex]);
} else {
//goto the quiz results page.  quiz is complete
}

• ###### 8. Re: How to create a Random Timeline with checks?

quiz still repeating questions however it was because I had the

initial script in every frame under my actions layer. That

probably reset the the script to start all over again

and caused an infinite loop. I have rectified by having the scrip

t only in my first frame.

It works like a dream.

Thank you very much

• ###### 9. Re: How to create a Random Timeline with checks?

you're welcome.