A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to create variables to hold radiobutton data for use in quiz

Hybrid View

  1. #1
    Senior Member
    Join Date
    Nov 2006
    Posts
    101

    How to create variables to hold radiobutton data for use in quiz

    Hi,

    I'm creating a quiz, and as yet, have just created the first question. It has 4 multiple choice answers, one of which is correct. I've used radiobuttons for these and have created an event listener to check for the selected option (below):

    _global.q1answer;

    var answerListener:Object = new Object();
    answerListener.click = function(eventObject:Object)
    {
    var question1Label:String = eventObject.target.selection.data;
    trace(question1Label);
    }
    question1.addEventListener("click", answerListener);

    next_btn.onRelease = function() {
    q1answer = question1Label;
    nextFrame();
    };


    The trace returns the correct value that is held in the data parameter of each radiobutton.

    However, I want to be able to manipulate this value further e.g. to check whether the answers are correct and then output feedback on incorrect answers etc at the end of the quiz. I used a global variable to hold this value and just tried to call it in, in a dynamic text field (q1_txt) in the next frame with the following code, but it keeps saying 'undefined':

    q1_txt.text = _global.q1answer;

    Can someone please point out what may be the problem, and whether there is a better way of doing what I'm trying to do.

    I can post the file if you want, and would appreciate it if you could help me out.

    Thanks

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    'question1Label' is a local variable to the 'answerListener.click = function'. So move where you are setting it from the next button to within the function.
    Code:
    stop();
    _global.q1answer;
    var answerListener:Object = new Object();
    answerListener.click = function(eventObject:Object) {
    	var question1Label:String = eventObject.target.selection.data;
    	trace(question1Label);
    	_global.q1answer = question1Label;
    };
    question1.addEventListener("click", answerListener);
    next_btn.onRelease = function() {
    	nextFrame();
    };

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center