-2

I am new to ActionScript-3 and I am attempting to make a game to learn more.

For every picture that is displayed I want there to be 4 choices (buttons) and only one of them to be the correct one. But how can I make it so that the text from the buttons will be random.

As you can see I've made it so the 4th button is always the correct answer. I don't want to make all this thing for every picture that is displayed...to much pointless code.

Can anybody help me? If you need extra information I will gladly provide it.

var k:int;
for(k=1;k<=3;k++)
{
GAME.variante.buttonMode=true;
GAME.variante.addEventListener(MouseEvent.MOUSE_OVER,mouse_over_variante);
GAME.variante.addEventListener(MouseEvent.MOUSE_OUT,mouse_out_variante);
GAME.variante.varianta_corecta.addEventListener(MouseEvent.CLICK,variante);
GAME.variante.varianta_gresita1.addEventListener(MouseEvent.CLICK,variante_gresiteunu);
GAME.variante.varianta_gresita2.addEventListener(MouseEvent.CLICK,variante_gresitedoi);
GAME.variante.varianta_gresita3.addEventListener(MouseEvent.CLICK,variante_gresitetrei);


GAME.varianta1.text = "Cameleon";
GAME.varianta2.text = "Snake";
GAME.varianta3.text = "Frog";
GAME.varianta4.text = "Snail";

function variante_gresiteunu(e:MouseEvent){
if (varianta_gresita_apasata1 == 1){
totalScore -= score_variante_gresite;
GAME.text1.text = totalScore;
    varianta_gresita_apasata1 = 2;
    }
}
function variante_gresitedoi(e:MouseEvent){
if  (varianta_gresita_apasata2 == 1){
totalScore -= score_variante_gresite;
GAME.text1.text = totalScore;
    varianta_gresita_apasata2 = 2;
}
}
function variante_gresitetrei(e:MouseEvent){
if  (varianta_gresita_apasata3 == 1){
totalScore -= score_variante_gresite;
GAME.text1.text = totalScore;
    varianta_gresita_apasata3 = 2;
}
}
}
GAME.extra_points.visible = false;
function variante (e:MouseEvent) {
if (GAME.stichere.sticker1.currentFrame == (1)){
GAME.extra_points.visible = true;
GAME.extra_points.plus_ten1.gotoAndPlay(1);
}
//go to great job screen
GAME.greatJob.stars.gotoAndPlay(1);
GAME.greatJob.visible = true;
}
function mouse_over_variante (e:MouseEvent) {
trace(e.target.name);
e.target.gotoAndPlay(1);
}
function mouse_out_variante (e:MouseEvent) {
e.target.gotoAndStop(1);
}
4

1 回答 1

0

You like to have 4 images and they will be tested right? The text below the images will be randomness. I saw your code and I confess I was confused. I made a different one. I undestand that this code is a little diferent of what you ask, but i think it will > give you some new ideas and help you on your app...

//start button added on the sceen named f3toc. I give a function name for him f3roll.
f3toc.addEventListener(MouseEvent.CLICK,f3roll);

function f3roll(e:MouseEvent):void{

//creating variables for the picture.
var bola:Number
var quadrado:Number
var pentagono:Number
//Here is just a randomization code, you can change it to the what you want to use after the =

    bola = Math.ceil(Math.random() * 10);
    pentagono = Math.ceil(Math.random() * 10);
    f3res1_txt.text = String (bola + 8 + 8);
    f3res2_txt.text = String(bola - 1 + bola);
    f3res3_txt.text = String (pentagono + 10 - bola);

//converting number to string so we can put tem into the text fields. 
var pentagonotring:String = pentagono.toString();
var bolastring:String = bola.toString();

//function to check wen the name is correct. each wrong do nothing and every correct add 1 to a variable, in the end wen this variable reach 3 it does something.

    f3check_bnt.addEventListener (MouseEvent.CLICK, f3check);
function f3check (e:MouseEvent):void{
    if (f3inp2_txt.text == pentagonotring){
        f3ver_ext2.text = "Correct"
        } else {f3ver_ext2.text = "Wrong";}
    if (f3inp1_txt.text == bolastring){
        f3ver_ext1.text = "Correct"
        }else {f3ver_ext1.text = "Wrong";}

// function to check wen the variable pass reach 3  
pass = 0;
    if  (f3ver_ext1.text == "Correct"){
        pass++
    }
    if  (f3ver_ext2.text == "Correct"){
        pass++

    if  (pass == 3){
        nextFrame();
    }}}}
于 2013-08-24T05:54:02.743 回答