I'm new to flash and coding, I'm attempting to setup a quiz for students who are in elementary school. I have tried quiz creators but they don't do what i want them to do. I've tried captivate but that also doesn't support buttons that have images in them.
My project consists of the following.
the red _____
The images are buttons which I made with roll over effects, and sound. They also move to the next question when the correct answer is chosen.
What I want is for the Buttons to be randomized when the slide loads, so they are not always in the same spot.
I created a layer called actions for the actionscript so in that layer, I have tried to create an array but I cant seem to make it work properly, the buttons never move. After extensive Google searches on randomization I have the following code.
function Main() {
var button:Array = [];
button.push("choice1");
button.push("choice2");
button.push("choice3");
ShuffleArray(button);
trace(button);
}
function ShuffleArray(button:Array)
{
for (var i:int = button.length-1; i >=0; i--)
{
var randomIndex:int = Math.floor(Math.random()*(i+1));
var itemAtIndex:Object = button[randomIndex];
button[randomIndex] = button[i];
button[i] = itemAtIndex;
Needless to say I have no idea why its not randomizing. I'm sure I'm missing something, or not coded correctly.
If someone could please point me in the right direction, or assist with the code I would really appreciate that.
Thanks in advance.
use:
function Main() {
var button:Array = [];
button.push("choice1");
button.push("choice2");
button.push("choice3");
shuffle(button);
for(var i:int=0;i<button.length;i++){
button[i].x = 50+button[i].width*i;
}
}function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
}
I tried your formula, no luck. i changed the "a" in your formula, to button the name of the array and still no success. So here is what i have now.
function Main() {
var button:Array = [];
button.push("choice1");
button.push("choice2");
button.push("choice3");
shuffle(button);
for(var i:int=0;i<button.length;i++){
button[i].x = 50+button[i].width*i;
}
}
function shuffle(button:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = button.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = button[ivar];
button[ivar] = button[p];
button[p] = t;
}
}
again this is the actions layer, also the buttons were exported for actionscripting. I think im still doing something wrong or maybe, i inserted the wrong labels.
you should be seeing error messages. if not, check your publish settings to make sure you're publishing for as3.
then, if you have buttons with instance names "choice1" etc, use:
function Main() {
var button:Array = [];
button.push("choice1");
button.push("choice2");
button.push("choice3");
shuffle(button);
for(var i:int=0;i<button.length;i++){
getChildByName(button[i]).x = 50+getChildByName(button[i]).width*i;
}
}function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
}
I have tried this also, there were no errors that showed up however there is no change. the buttons remain on the same place/position on the stage.is there anything perhaps i should be doing differently?
I did check the publish settings its set to as3, the advanced settings had something about doc class but i have no idea what that is or how to use it.
copy and paste the trace output from:
function Main() {
var button:Array = [];
button.push("choice1");
button.push("choice2");
button.push("choice3");
shuffle(button);
for(var i:int=0;i<button.length;i++){
getChildByName(button[i]).x = 50+getChildByName(button[i]).width*i;trace(i,
button[i],getChildByName(button[i].name)
}
}function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
}
North America
Europe, Middle East and Africa
Asia Pacific