开发者

Creating quiz in flash/actionscript with questions passed through flashvars

I am getting questions from the database (just text) and then passing them to flash via flash vars. I want one question to be displayed then the user will answer (text) and click a button and then the next question will be displayed for them to answer and so on.

I am not hoping for overly specific advice but as I am very new to flash/actionscript am just looking for broad advice (or links ?) on how to approach this. Can I do it all from one frame just using actionscript ?

EDIT: I think what I am really after (assuming I am not way off track) is if all the questions should be handled at once which I guess will require some kind of loop that listens for some buttonclick event to move to the next question ....开发者_JAVA技巧. or be 'reloading' the flash movie and dealing with only 1 question at a time.

Thanks for any help.


I'd do this:

  1. Create a PHP file that has a whatever-delimited list of all your questions outputted onto it, for example:

    What is the time?#Where do you live?#How much water do you drink per day?#How old are you?

  2. Use URLLoader to load a list of all your questions in Flash.
  3. Create an Array containing all of your questions by using split("#") on the String that you've received from your PHP page via the URLLoader.

That should get you started.


I saw your edit, here's how I would do it:

//class var
private var answerHolder:Sprite = new Sprite();

private function createAnswers( answerArray:Array ){
    if(answerHolder.parent){ //Makes sure we have a parent, so we don't get an ugly error.
        answerHolder.parent.removeChild(answerHolder); //removes answerholder, cleans out previous answers
    }
    answerHolder = new Sprite(); //new empty sprite
    addChild(answerHolder); //Adds the new empty sprite
    for (var i in answerArray){
        var newAnswer:Answer = new Answer(); //have a movieclip with linkage set to Answer
        newAnswer.txt.text = answerArray[i]; //Have a text field in Answer with the instance name of txt
        newAnswer.x = 50;
        newAnswer.y = 100 + newAnswer.width * i;
        newAnswer.name = i;
        addChild(newAnswer);
        newAnswer.addEventListener(MouseEvent.MOUSE_DOWN, selectedChoice); //MAKE SURE to have imported MouseEvents!
    }
}
private function selectedChoice(e:MouseEvent) {
    trace('Selected ' + e.name);
}

This is no means completed code or anything (You will get an error because I didn't write a constructor, nor the questions, and I pulled answerArray out of thin air, you also need to addChild(answerHolder) too), it's something to get started :)

createAnswers() can be called again, when you have a new question - this is because the sprite that holds answerHolder is cleared.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜