A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Button Problem

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    13

    resolved [RESOLVED] Button Problem

    So i have a little problem, I'm creating a multiple choice quiz in AS3. At the minute the user is free to skip the question by clicking the next question button.

    What I'm trying to do is to hide the button and then have it re-appear once the user has clicked the correct answer. I know I'm going wrong somewhere but any help would be massively appreciated.

    I've put the code relating to the button in bold to highlight the problem.

    Thanks for your time.

    Code:
    stop();
    
    messageBox.text = "";					// Clears the Response box
    var correctAnswer:String = "2 Minutes";	// Sets correct answer for comparison
    var userAnswer:String;					//  with value from radio button group.
    var rbg:Object = rbtwo.group;		// Get the name of the radio button group from the first button.
    
    next_btn.enabled = false;
    
    next_btn.addEventListener(MouseEvent.CLICK, changeQuestion);
    
    btnCheck.addEventListener(MouseEvent.CLICK, checkAnswer);
    
    function checkAnswer(evt:MouseEvent):void {
    	userAnswer = String(rbg.selectedData);
    	if (userAnswer == correctAnswer) {
    	   messageBox.text = "Yes, " + userAnswer + " is the correct answer!";
    	   next_btn.enabled == true;
    	}
    	else {
    	   messageBox.text = "No, " + userAnswer + " is incorrect. Try again.";
    	}
    }
    
    function changeQuestion(event:MouseEvent):void {
    	if (userAnswer == correctAnswer) {
    		next_btn.enabled == true;
    	}
    	else{
    		next_btn.enabled = false;
    	}
    }
    
    next_btn.addEventListener(MouseEvent.CLICK, next15Click);
    
    function next15Click(event:MouseEvent):void
    {
           gotoAndPlay(21);
    };

  2. #2
    Junior Member
    Join Date
    Mar 2009
    Posts
    13
    Anybody have any ideas?

    Im new to AS3 so i understand my nextquestion eventhandler may be totally wrong.

    But a little guidance would be greatly appreciated.

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You are using double-equals (==) instead of assignment equals (=). This results in a rather useless comparison and a boolean result instead of actually changing the value of next_btn.enabled.

  4. #4
    Junior Member
    Join Date
    Mar 2009
    Posts
    13
    Thanks for the help.

    I've taken out my changeQuestion event holder as I presumed it wasn't doing anything.

    Basically, this code returns no errors but the button remains on stage the whole time.

    Any ideas what i'm missing?

    Thanks

    Code:
    import flash.display.MovieClip;
    stop();
    
    messageBox.text = "";				
    var correctAnswer:String = "2 Minutes";
    var userAnswer:String;					
    var rbg:Object = rbtwo.group;		
    
    next_btn.enabled = false;
    
    btnCheck.addEventListener(MouseEvent.CLICK, checkAnswer);
    
    function checkAnswer(evt:MouseEvent):void {
    	userAnswer = String(rbg.selectedData);
    	if (userAnswer == correctAnswer) {
    	   messageBox.text = "Yes, " + userAnswer + " is the correct answer!";
    	   next_btn.enabled = true;
    	}
    	else {
    	   messageBox.text = "No, " + userAnswer + " is incorrect. Try again.";
    	}
    }
    
    next_btn.addEventListener(MouseEvent.CLICK, nextframe);

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Oh, if you actually want the button off stage, you'll have to remove it rather than just set it to enabled = false.

    Code:
    import flash.display.MovieClip;
    stop();
    
    messageBox.text = "";				
    var correctAnswer:String = "2 Minutes";
    var userAnswer:String;					
    var rbg:Object = rbtwo.group;		
    
    removeChild(next_btn);
    
    btnCheck.addEventListener(MouseEvent.CLICK, checkAnswer);
    
    function checkAnswer(evt:MouseEvent):void {
    	userAnswer = String(rbg.selectedData);
    	if (userAnswer == correctAnswer) {
    	   messageBox.text = "Yes, " + userAnswer + " is the correct answer!";
    	   addChild(nextBtn);
    	}
    	else {
    	   messageBox.text = "No, " + userAnswer + " is incorrect. Try again.";
    	}
    }
    
    next_btn.addEventListener(MouseEvent.CLICK, nextframe);

  6. #6
    Junior Member
    Join Date
    Mar 2009
    Posts
    13
    awesome!, works a dream, thanks so much.

Tags for this Thread

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