actionscript 3 - AS3: Maintain Checkbox state when returning to a frame with checkboxes -


so asked question yesterday how control state of checkboxes here: getting checkboxes retain state on return frame

however has caused problem. whilst values of checkboxes retained, relationship objects represent not.. example, on return home screen checkbox value filled in true button that checkbox represents won't visible until uncheck , recheck box.

i've been trying store boolean value of checkbox in variable , re use upon return screen don't' understand enough of syntax work.

looking @ code below i'm wondering whether it's because i'm setting default state of button visibility right @ start of code false? need area_1_btn.visible check boolean state?

any appreciated i'm getting more , more frustrated @ lack of understanding heh.

import flash.events.event;  /* ensures checkboxes begin in off state.*/ area_1_btn.visible = false; area_1_chk.visible = true; area_2_btn.visible = false; area_2_chk.visible = true; showall_chk.visible = true;  /* defines show checkbox , sets states true/false*/ showall_chk.addeventlistener(event.change, togglemulti, false, 0, true); function togglemulti(e:event):void {     var sac:boolean = e.target.selected;     if (sac)     {         area_1_chk.selected = true;         area_1_btn.visible = true;         area_2_chk.selected = true;         area_2_btn.visible = true;     }     else     {         area_1_chk.selected = false;         area_1_btn.visible = false;         area_2_chk.selected = false;         area_2_btn.visible = false;     } }  /* toggles button state*/ function togglearea_1_btn(e:event):void {     var a1b:boolean = e.target.selected;     if (a1b)     {         area_1_btn.visible = true;     }     else     {         area_1_btn.visible = false;     }     /* previous method toggling button state*/ } function togglearea_2_btn(e:event):void {     area_2_chk.selected ? area_2_btn.visible = true:area_2_btn.visible = false; }  /* listens state of checkbox , switches button on*/ area_1_chk.addeventlistener(event.change, togglearea_1_btn, false, 0, true); area_2_chk.addeventlistener(event.change, togglearea_2_btn, false, 0, true);  /* listens mouse click , instructions function below*/ area_1_btn.addeventlistener(mouseevent.click, a1_clicktogotoandstopatframe); area_2_btn.addeventlistener(mouseevent.click, a2_clicktogotoandstopatframe);  function a1_clicktogotoandstopatframe(event:mouseevent):void {     gotoandstop(2); } function a2_clicktogotoandstopatframe(event:mouseevent):void {     gotoandstop(3); }  stop(); 

here optimizations , additions should trick:

import flash.events.event; import flash.events.mouseevent;  //a method can call set visibility of checkbox related items. pass in false hide them function showcheckboxes(val:boolean = true):void {     area_1_chk.visible = val;     area_2_chk.visible = val;     showall_chk.visible = val;     area_1_btn.visible = val;     area_2_btn.visible = val;      if(val) setbuttonvisibility();  //if showing, show/hide buttons based off check box value }  //this update button visibility based off checkbox selected value. function setbuttonvisibility(e:event = null):void {     area_1_btn.visible = area_1_chk.selected;     area_2_btn.visible = area_2_chk.selected; }  function togglemulti(e:event):void {     area_1_chk.selected = showall_chk.selected;     area_2_chk.selected = showall_chk.selected;     setbuttonvisibility(); }  function buttonclick(e:event):void {     showcheckboxes(false); //hide since we're moving new frame      switch(e.currenttarget) {   //e.currenttarget button clicked         case area_1_btn:             gotoandstop(2);             break;          case area_1_btn:             gotoandstop(3);             break;     } }  //add listeners showall_chk.addeventlistener(event.change, togglemulti, false, 0, true); area_1_chk.addeventlistener(event.change, setbuttonvisibility, false, 0, true); area_2_chk.addeventlistener(event.change, setbuttonvisibility, false, 0, true); area_1_btn.addeventlistener(mouseevent.click, buttonclick); area_2_btn.addeventlistener(mouseevent.click, buttonclick);  showcheckboxes(); //call right visibility updates when frame loads.  stop(); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -