问题
thanks for taking the time to read this.
let me preface this by saying I'm extremely new to Flash/Actionscript and haven't done any coding in about 15years. Basically I've been asked by my employer to create a presentation for a client. This presentation uses checkboxes to display different segments of an image (actually buttons). These buttons in turn link to other frames with information about the section they clicked on.
So far all is working, I've got all my checkboxes linked to buttons with a check all/ uncheck all button .. where I'm struggling is getting flash to remember what state the checkboxes were in when I left the 'map frame'.
Area_1_Chk.addEventListener(Event.CHANGE, toggleArea_1_Btn, false, 0, true);
Area_2_Chk.addEventListener(Event.CHANGE, toggleArea_2_Btn, false, 0, true);
/* Ensures that all checkboxes begin in the off state.
*/
Area_1_Btn.visible = false
Area_2_Btn.visible = false
/* Defines the Show All Checkbox and sets states to 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;
}
}
function toggleArea_1_Btn(e:Event):void
{
Area_1_Chk.selected ? Area_1_Btn.visible = true : Area_1_Btn.visible = false;
}
function toggleArea_2_Btn(e:Event):void
{
Area_2_Chk.selected ? Area_2_Btn.visible = true : Area_2_Btn.visible = false;
}
Area_1_Btn.addEventListener(MouseEvent.CLICK, A1_ClickToGoToAndStopAtFrame);
Area_2_Btn.addEventListener(MouseEvent.CLICK, A2_ClickToGoToAndStopAtFrame);
/* Sets link to frame */
function A1_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
gotoAndStop(2);
}
function A2_ClickToGoToAndStopAtFrame(event:MouseEvent):void
{
gotoAndStop(3);
}
stop();
回答1:
Easiest thing would be to put them on a layer that continues to exist in frame 3, but make them invisible from code.
Other options include having 2 variables that hold the states and manually assigning them when returning to the frame (variables are accessible across frames), never changing the frame at all (just showing and hiding items), put them on frame 3 outside the stage area, etc..
来源:https://stackoverflow.com/questions/25746009/getting-checkboxes-to-retain-their-state-on-return-to-frame