Radio Button Bug .enabled?
I have been writing a fairly complex testing application for my job, and have been agonizing over this problem for over a month.
I have created a dynamic testing application that reads from XML, and my radiobutton class works splendidly, except for that when a user is prompted to review the exam, and the enabled parameter is set to false (no longer allowing a user to change the submitted submitted radiobutton answers), I loose the formatted text size for that radio button label. I am dealing with ADA issues, so allowing them to see the proper text size when reviewing their exam is of utmost importance. I am with them being grayed out, i just need to be able to maintain that the buttons are disabled, but the text size remains the same. I have tried re-applying my format to the radio buttons after setting rb.enabled = false; but it doesn't do anything....
Any help would be greatly appreciated.....
Attach Code
stop();
//import flash.display.DisplayObject;
//import flash.events.*;
import fl.managers.FocusManager;
import flash.display.InteractiveObject;
//var child_yo: DisplayObject = new DisplayObject ();
// addChild(child_yo);
stage.focus = this;
this.addEventListener(KeyboardEvent.KEY_UP, _onKeyDown);
//square_listener.addEventListener(KeyboardEvent.KEY_DOWN, _onKeyDown);
function _onKeyDown(event:KeyboardEvent) {
if (event.keyCode == 39 && question_cycle + 1 < xmlData_2.questions.length())
{
next_question(null);
trace("upKey");
}
if (event.keyCode == Keyboard.ENTER && question_cycle + 1 < xmlData_2.questions.length())
{
next_question(null);
trace("upKey");
}
if (event.keyCode == 37 && question_cycle > 0)
{
last_question(null);
trace("downKey");
}
trace(question_cycle +"<"+ xmlData_2.questions.length);
trace("keyDownHandler: " + event.keyCode + "this is enter!");
//trace("ctrlKey: " + event.ctrlKey);
//trace("keyLocation: " + event.keyLocation);
//trace("shiftKey: " + event.shiftKey);
//trace("altKey: " + event.altKey);
stage.focus = this;
}
//this is a fix for messed up keybourd input.
var myFM:FocusManager = new FocusManager (masterFocus); var nextFMComponent:InteractiveObject; stage.stageFocusRect = false; setMasterFocus (); function setMasterFocus ():void { masterFocus.focusRect = false; masterFocus.addEventListener (FocusEvent.FOCUS_OUT, FocusOutMaster); nextFMComponent = masterFocus; myFM.setFocus (nextFMComponent); } function FocusOutMaster (event:FocusEvent):void { nextFMComponent = masterFocus; myFM.setFocus (nextFMComponent); }
//this formats text like a style sheet.
var error_Format:TextFormat = new TextFormat();
error_Format.size = font_size;
error_Format.color = 0xFFFFFF;
var nameFormat:TextFormat = new TextFormat();
nameFormat.size = font_size;
nameFormat.color = 0x226099;
nameFormat.font = "Arial Rounded MT Bold";
var name_box = new TextField();
name_box.multiline = false;
name_box.width = 330;
name_box.x = 30;
name_box.y = 15;
addChild(name_box);
if (first_name_value.length + last_name_value.length > 18){
var Combo_Name:String = first_name_value + " " + last_name_value;
name_box.text = Combo_Name.substring(0,19) + "...";
name_box.setTextFormat(nameFormat);
trace(Combo_Name +" adslkj;ffffa;lskdjfa;lksdjf;laksjdf;lakjsd;lfkajsdf");
} else {
name_box.text = "test session for: " + first_name_value + " " + last_name_value;
name_box.setTextFormat(nameFormat);
}
//this is the background osha logo
var logo_back_tran:logo_back_real = new logo_back_real;
addChild(logo_back_tran);
logo_back_tran.gotoAndPlay(1);
logo_back_tran.x = 300;
logo_back_tran.y = 220;
var title_holder:TextField = new TextField;
title_holder.type = TextFieldType.DYNAMIC;
title_holder.wordWrap = true;
//term_holder.autoSize = TextFieldAutoSize.LEFT;
title_holder.width = 500;
title_holder.height = 300;
title_holder.multiline = true;
//term_holder.setTextFormat(my_form_Format);
title_holder.x = 25
title_holder.y = 55;
title_holder.htmlText = xmlData.title_;
title_holder.setTextFormat(nameFormat);
addChild(title_holder);
var title_holder_scroller:UIScrollBar = new UIScrollBar();
title_holder_scroller.direction = ScrollBarDirection.VERTICAL;
title_holder_scroller.scrollTarget = title_holder;
title_holder_scroller.height = 324;
title_holder_scroller.move(580, 44);
addChild(title_holder_scroller);
//this represents the x position of the original question
var questionX:int = 60;
//this represents the y position of the original question
var questionY:int = 75;
//This represents the x position of the radio buttons
var answerX:int = 95;
//var answerY:int = question_answer_spacer;
var question_answer_spacer:int;
var spacing:int = 25;
var TestNumFieldX:int = 480;
var TestNumFieldY:int = 15;
var questionField = new TextField();
var TestNumField = new TextField();
var ErrorHandlerField = new TextField();
var theUserAnswer:int;
var theRealAnswer:Array = new Array;
var stored_answer_array:Array = new Array;
var stored_error_array:Array = new Array;
var stored_error_output:Array = new Array;
var stored_error_output_box:String = new String;
//these monitor that next and back buttons disappear and appear appropiatly
var back_but_toggler:Boolean = new Boolean;
var next_but_toggler:Boolean = new Boolean;
var help_but_toggler:Boolean = new Boolean;
var only_once_finish_but:Boolean = new Boolean;
//var question_scroller_toggler:Boolean = new Boolean;
//question_scroller_toggler = false;
var alpha_down_timer:Timer = new Timer(1, 100);
var alpha_up_timer:Timer = new Timer(1, 100);
//this is the new instance of the movie clip behind error handling for "are you sure you'd like to quite"
var newFinish:finish = new finish();
//this checks whether or not the user has submitted his/her exam...maybe cuz theres nothing below it
//variable for checking if frame two has arrived for flyout menu back button
one_two_frame_checker = true;
//variable for checking that finish_but children are not constantly added...
only_once_finish_but = true;
//these are the visual labels for the buttons
var next_graphic:next_arrow = new next_arrow();
var back_graphic:back_arrow = new back_arrow();
var question_graphic:question_mark = new question_mark();
var check_graphic:check_mark = new check_mark();
var check_or_x:results_graphics = new results_graphics();
check_or_x.x = 550;
check_or_x.y = 350;
var long_question_back:long_question_backer = new long_question_backer();
long_question_back.x = 30;
long_question_back.y = 60;
var error_border:error_png = new error_png();
error_border.x = 100;
error_border.y = 340;
ErrorHandlerField.x = 125;
ErrorHandlerField.y = 342;
//this formats text like a style sheet.
var myFormat:TextFormat = new TextFormat();
myFormat.size = font_size;
//myFormat.width = 400;
myFormat.font = "Times New Roman";
var num_fade_out:int = 1;
var num_fade_in:int;
var temp_holder;
//this keeps track of output for the stored_error_output:Array
var d:int = 0
//this condition substantiates that the next button has been clicked
back_but_toggler = true;
next_but_toggler = false;
help_but_toggler = true;
var holder_buts:MovieClip = new MovieClip();
holder_buts.x = 0;
holder_buts.y = 0;
addChild(holder_buts);
var holder:MovieClip = new MovieClip();
holder.x = 0;
holder.y = 0;
addChild(holder);
var return_but:Button = new Button();
return_but.label = "return to exam";
return_but.x = 220;
return_but.y = 270;
var end_but:Button = new Button();
end_but.label = "grade exam";
end_but.x = 350;
end_but.y = 270;
var next_but:Button = new Button();
next_but.label = "next";
next_but.x = 488;
next_but.y = 414;
next_graphic.x = 590;
next_graphic.y = 411;
holder_buts.addChild(next_but);
var back_but:Button = new Button();
back_but.label = "back";
back_but.x = 378;
back_but.y = 414;
back_graphic.x = 340;
back_graphic.y = 411;
var finish_but:Button = new Button();
finish_but.label = "Grade Exam";
finish_but.x = 20;
finish_but.y = 414;
check_graphic.x = 125;
check_graphic.y = 414;
var back_to_results:Button = new Button();
back_to_results.label = "Back to Results";
back_to_results.x = 20;
back_to_results.y = 414;
var help_but:Button = new Button();
help_but.label = "General Help";
help_but.x = 320;
help_but.y = 105;
var tip_but:Button = new Button();
tip_but.label = "Tip";
tip_but.x = 172;
tip_but.y = 414;
question_graphic.x = 285;
question_graphic.y = 410;
var question_scroller:UIScrollBar = new UIScrollBar();
question_scroller.direction = ScrollBarDirection.VERTICAL;
question_scroller.height = 85;
question_scroller.x= 597;
question_scroller.y= 64;
holder_buts.addChild(next_graphic);
//this gets the flyout menu ready to flow in frame 2, and checks if frame 3 has been done
if (frame_3_checker == false){
tween_handler.removeChild(size_picker);
tween_handler.removeChild(_last_continue_fly);
tween_handler.addChild( _back_fly);
tween_handler.addChild(help_but);}
help_but.addEventListener(MouseEvent.CLICK, general_help);
function general_help(event:MouseEvent):void {
tween_handler.fly_out_text.htmlText = xmlData.general_help;
}
tip_but.addEventListener(MouseEvent.CLICK, tips);
function tips(event:MouseEvent):void {
x_visible_timer.reset();
x_visible_timer.start();
//this toggles "clickability" for the button in question
tip_but.removeEventListener(MouseEvent.CLICK, tips);
trace("tip button is working great" + one_two_frame_checker)
}
var question_cycle:int = -1 ;
next_but.addEventListener (MouseEvent.CLICK, next_question);
back_but.addEventListener (MouseEvent.CLICK, last_question);
finish_but.addEventListener (MouseEvent.CLICK, GradeError);
return_but.addEventListener (MouseEvent.CLICK, back_test);
end_but.addEventListener (MouseEvent.CLICK, end_test);
back_to_results.addEventListener (MouseEvent.CLICK, back_results);
function back_results(event:MouseEvent):void {
gotoAndStop(3);
removeChild(holder);
removeChild(holder_buts);
if(question_cycle < 0){
removeChild(title_holder);
removeChild(title_holder_scroller);
}}
function back_test(event:MouseEvent):void {
holder.removeChild(newFinish);
holder.removeChild(return_but);
holder.removeChild(end_but);
}
function end_test(event:MouseEvent):void {
//holder.removeChild(newFinish);
//holder.removeChild(return_but);
//holder.removeChild(end_but);
removeChild(holder);
removeChild(holder_buts);
removeChild(finish_but);
holder_buts.removeChild(check_graphic);
gotoAndStop(3);
}
function next_question(event:MouseEvent):void {
if(question_cycle < 0){
removeChild(title_holder);
removeChild(title_holder_scroller);
logo_back_tran.gotoAndPlay(48);
holder_buts.addChild(error_border);
//this adds check graphics after the error border
if(test_done_checker==true){
holder_buts.addChild(check_or_x);
}
}
//if (question_scroller_toggler == true)
//{holder.removeChild(question_scroller);
//question_scroller_toggler = false;
//trace("question scroller toggler is" + question_scroller_toggler)
//}
question_cycle = question_cycle + 1;
trace("up");
toggle_questions();
//this toggles the content of the flyout menu
tween_handler.fly_out_text.htmlText = xmlData_2.questions[question_cycle].question_tip;
tween_handler.fly_scroller.update();
if (help_but_toggler == true && question_cycle > -1)
{
holder_buts.addChild(tip_but);
holder_buts.addChild(question_graphic);
question_graphic.gotoAndPlay(1);
help_but_toggler = false;
}
if (back_but_toggler == true && question_cycle > 0)
{
holder_buts.addChild(back_but);
holder_buts.addChild(back_graphic);
back_graphic.gotoAndPlay(1);
back_but_toggler = false;
}
trace(question_cycle + 1 + " vs. " + xmlData_2.questions.length());
if (question_cycle + 1 == xmlData_2.questions.length())
{
holder_buts.removeChild(next_but);
holder_buts.removeChild(next_graphic);
next_but_toggler = true;
}
}
function last_question (event:MouseEvent):void {
question_cycle = question_cycle -1;
//if (question_scroller_toggler == true)
//{holder.removeChild(question_scroller);
//question_scroller_toggler = false;
//trace("question scroller toggler is" + question_scroller_toggler)
//}
trace("down");
toggle_questions();
//this changes the content of the flyout menu box as well
tween_handler.fly_out_text.htmlText = xmlData_2.questions[question_cycle].question_tip;
tween_handler.fly_scroller.update();
if (question_cycle < 1)
{
holder_buts.removeChild(back_but);
holder_buts.removeChild(back_graphic);
back_but_toggler = true;
}
if (next_but_toggler == true)
{holder_buts.addChild(next_but);
holder_buts.addChild(next_graphic);
next_graphic.gotoAndPlay(1);
next_but_toggler = false;
}
}
//this is total keybourd functionality
var myGroup:RadioButtonGroup = new RadioButtonGroup("group1");
myGroup.addEventListener(Event.CHANGE, changeHandler);
function toggle_questions():void {
questionField.text = xmlData_2.questions[question_cycle].question_text;
questionField.autoSize = TextFieldAutoSize.LEFT;
questionField.multiline = true;
questionField.width = 500;
questionField.wordWrap = true;
questionField.x = questionX;
questionField.y = questionY;
questionField.selectable = true;
back_but.alpha = 1;
trace (question_answer_spacer + "here is the spacing");
while (holder.numChildren > 0) {
holder.removeChild(holder.getChildAt(0));
}
trace(holder.numChildren+"wazoo");
//this is the boundry box for larger questions
if (questionField.numLines > 3) {
holder.addChild(long_question_back);
long_question_back.gotoAndPlay(1);
}
holder.addChild(questionField);
questionField.setTextFormat(myFormat);
if (questionField.numLines > 3) {
trace("Yes O YEs baby Numlines are more than 3!")
questionField.autoSize = TextFieldAutoSize.NONE;
questionField.height = 75;
trace(questionField.height+"this is the height");
holder.addChild(question_scroller);
//this scroll target must remain here to reset properly
question_scroller.scrollTarget = questionField;
questionField.text = xmlData_2.questions[question_cycle].question_text;
questionField.setTextFormat(myFormat);
question_scroller.update();
//question_scroller_toggler = true;
};
question_answer_spacer = questionField.height;
if (questionField.numLines > 3) {
question_answer_spacer = questionField.height + 8 ;
}
for(var i:int = 0; i < xmlData_2.questions[question_cycle].choice.length(); i++) {
var rb:RadioButton = new RadioButton();
//trace("for loop is working")
rb.textField.autoSize = TextFieldAutoSize.LEFT;
rb.label = xmlData_2.questions[question_cycle].choice[i];
rb.textField.setTextFormat(myFormat);
rb.name = "googles"
rb.group = myGroup;
rb.value = i + 1;
rb.x = answerX;
rb.y = question_answer_spacer + 80 + (i * spacing);
//this checks to see if 'test done checker' has been substantiated, turns off enabled buttons, and makes sure that the old answers are reguritated.
if (test_done_checker==true){
rb.enabled = false;
if (rb.value == final_answer_array[question_cycle]){
rb.selected = true;
}
}
//this makes sure that previously answered questions are selected
if (rb.value == stored_answer_array[question_cycle]){
rb.selected = true;
}
//rb.setTextFormat(myFormat);
rb.setStyle("textFormat", myFormat);
holder.addChild(rb);
//holder.rb.setTextFormat(myFormat);
}
//trace (holder.numChildren +"Kazoo!");
TestNumField.text = "question " + (question_cycle + 1) + " of " + xmlData_2.questions.length();
TestNumField.autoSize = TextFieldAutoSize.LEFT;
TestNumField.x = TestNumFieldX;
TestNumField.y = TestNumFieldY;
holder.addChild(TestNumField);
TestNumField.setTextFormat(nameFormat);
//this checks to see that the test has not not been completed, and that the user has cycled through all of the questions
if (question_cycle + 1 == xmlData_2.questions.length() && test_done_checker==false && only_once_finish_but == true){
addChild(finish_but);
holder_buts.addChild(check_graphic);
check_graphic.gotoAndPlay(1);
trace("boobies...there's a problem")
only_once_finish_but = false;
}
//this tells you what you answered, and if it was wrong
if (test_done_checker==true){
holder.addChild(ErrorHandlerField);
ErrorHandlerField.text = grading_results_feedback[question_cycle];
ErrorHandlerField.autoSize = TextFieldAutoSize.LEFT;
ErrorHandlerField.setTextFormat(error_Format);
if (grading_results_feedback[question_cycle]== "incorrect"){
check_or_x.gotoAndPlay(2);
}
else{
check_or_x.gotoAndPlay(17);}
}
//this makes sure that the buttons don't overlap the flyout menu
removeChild(tween_handler);
addChild(tween_handler);
}
//this adds the back to results button to holder_buts if test_done_checker is true
if (test_done_checker==true){
holder_buts.addChild(back_to_results);
}
function changeHandler(event:Event) {
theUserAnswer = event.target.selectedData;
stored_answer_array[question_cycle] = theUserAnswer;
trace(theUserAnswer);
trace (stored_answer_array);
trace (stored_answer_array[question_cycle] + "Array is on");
}
trace (stored_answer_array[question_cycle] + "Array is on outside");
function GradeError (event:MouseEvent) {
for (var i:int = 0; i < xmlData_2.questions.length();i++)
{stored_error_array[i] = stored_answer_array[i]
if (stored_error_array[i]== null){
stored_error_output.push(i+1);
//d+1
trace(stored_error_output+"what does this look like working?");
}
}
//this prompts the error handler for "are you sure you want to quit"
if(stored_error_output[0] == null){
holder.addChild(newFinish);
holder.addChild(return_but);
holder.addChild(end_but);
newFinish.x = 300;
newFinish.y = 200;
check_graphic.gotoAndPlay(13);
}
//this is the error handling for unanswered questions
else{
holder.addChild(ErrorHandlerField);
trace(stored_error_output[0] +"!"+ stored_error_output[1]+"!"+ stored_error_output[2]+"!"+ stored_error_output[3] +"!"+ stored_error_output[4])
stored_error_output_box = stored_error_output.toString();
ErrorHandlerField.text = "Please answer " + stored_error_output_box + " before finishing test";
ErrorHandlerField.autoSize = TextFieldAutoSize.LEFT;
ErrorHandlerField.setTextFormat(error_Format);
trace(stored_error_output + "this is what your checking for")
stored_error_output = [];}
}