james_martin Posted January 5, 2010 Share Posted January 5, 2010 Hello Newbie Alert!! I am having some problems with a small survey swf i am making in actionscript 3. I have multiple choice questions on different frames using radio buttons and i need the users selections shown in a dynamic text button along each frame and also on the last frame of the survey. Another problem i am getting is i need the last radio button clicked to be stored, so if the user clicks lets say 'rb_2' on frame 1, clicks next to go to frame 2, then if they were to go back to frame 1 again 'rb_2' is still selected. Thought it would be easy using the 'Shared Object Class' but from reading tutorials i cannot get it working. Is this the best way or should i be looking into another solution? Cheers James Quote Link to comment https://forums.phpfreaks.com/topic/187333-storing-radio-button-selections/ Share on other sites More sharing options...
james_martin Posted January 6, 2010 Author Share Posted January 6, 2010 Sorry i should have posted some of my code really!! I left it out originally as it just wasn't working but i have got parts of it working now. Still using the 'sharedObject' class i have got the users selection shown on each frame in dynamic text boxes and the radio button on frame one is stored so if you click 'rb_3' on frame 1, click next for frame 2 then go back again to frame 1 again 'rb_3' will still be selected. Problem is this only works for frame 1, the stored data for frame 2 is now saving. I have a test link of http://www.neufster.com/testing/test.swf to explain. If anyone can help get this code working? I am sure that the problem lies in calling '(so.data["value"] ==".....") on both frame 1 and 2 or am i wrong? the full code i am using is : Frame 1> // Import Radio Button Controls. import fl.controls.RadioButtonGroup; // Set Variable of Rb Group. var rbGroup:RadioButtonGroup = new RadioButtonGroup( "myRBGroup" ); // Set Variable of Shared Object. var so:SharedObject = SharedObject.getLocal("options"); // Assign Group and Values to Rb's. rb_1.group=rbGroup; rb_1.value = "macbook"; rb_2.group=rbGroup; rb_2.value = "macbook pro"; rb_3.group=rbGroup; rb_3.value = "imac"; rb_4.group=rbGroup; rb_4.value = "emac"; rb_5.group=rbGroup; rb_5.value = "mac pro"; rb_6.group=rbGroup; rb_6.value = "mac mini"; // Add Event Listeners on Rb's. rb_1.addEventListener(MouseEvent.CLICK, showResult); rb_2.addEventListener(MouseEvent.CLICK, showResult); rb_3.addEventListener(MouseEvent.CLICK, showResult); rb_4.addEventListener(MouseEvent.CLICK, showResult); rb_5.addEventListener(MouseEvent.CLICK, showResult); rb_6.addEventListener(MouseEvent.CLICK, showResult); //Define function on Rb's. function showResult(event:MouseEvent):void { switch (rbGroup.selection) { case rb_1 : stage_1_txt.text = "macbook" ; break; case rb_2 : stage_1_txt.text="macbook pro"; break; case rb_3 : stage_1_txt.text="imac"; break; case rb_4 : stage_1_txt.text="emac"; break; case rb_5 : stage_1_txt.text="mac pro"; break; case rb_6 : stage_1_txt.text="mac mini"; break; } } // Frame Navigation. stop(); next_btn.addEventListener(MouseEvent.MOUSE_UP,nxt); // Define and Trace Rb Choice on Button. // Flush so to retrieve in later use. function nxt(e:MouseEvent):void { gotoAndStop(2); trace( rbGroup.selection.value ); so.data["value"] = rbGroup.selection.value; so.data["value"] = rbGroup2.selection.value; so.flush(); } // Define Radio Button according to last Click. if ( so.data["value"] == "macbook" ) { rbGroup.selection = rb_1; stage_1_txt.text="macbook"; } if ( so.data["value"] == "macbook pro" ) { rbGroup.selection = rb_2; stage_1_txt.text="macbook pro"; } if ( so.data["value"] == "imac" ) { rbGroup.selection = rb_3; stage_1_txt.text="imac"; } if ( so.data["value"] == "emac" ) { rbGroup.selection = rb_4; stage_1_txt.text="emac"; } if ( so.data["value"] == "mac pro" ) { rbGroup.selection = rb_5; stage_1_txt.text="mac pro"; } if ( so.data["value"] == "mac mini" ) { rbGroup.selection = rb_6; stage_1_txt.text="mac mini"; } Second Frame > // Set Variable of Rb Group. var rbGroup2:RadioButtonGroup=new RadioButtonGroup("Group 2"); // Assign Group and Values to Rb's. rb_7.group=rbGroup2; rb_7.value = "one month"; rb_8.group=rbGroup2; rb_8.value = "six months"; rb_9.group=rbGroup2; rb_9.value = "one year"; rb_10.group=rbGroup2; rb_10.value = "two years"; rb_11.group=rbGroup2; rb_11.value = "three years"; rb_12.group=rbGroup2; rb_12.value = "four years"; // Add Event Listeners on Rb's. rb_7.addEventListener(MouseEvent.CLICK, showResult2); rb_8.addEventListener(MouseEvent.CLICK, showResult2); rb_9.addEventListener(MouseEvent.CLICK, showResult2); rb_10.addEventListener(MouseEvent.CLICK, showResult2); rb_11.addEventListener(MouseEvent.CLICK, showResult2); rb_12.addEventListener(MouseEvent.CLICK, showResult2); //Define function on Rb's. function showResult2(event:MouseEvent):void { switch (rbGroup2.selection) { case rb_7 : stage_2_txt.text="one month"; break; case rb_8 : stage_2_txt.text="six months"; break; case rb_9 : stage_2_txt.text="one year"; break; case rb_10 : stage_2_txt.text="two years"; break; case rb_11 : stage_2_txt.text="three years"; break; case rb_12 : stage_2_txt.text="four years"; break; } } // Frame Navigation. stop(); next2_btn.addEventListener(MouseEvent.MOUSE_UP,nxt2); back_btn.addEventListener(MouseEvent.MOUSE_UP,back); // Define and Trace Rb Choice on Button. function nxt2(e:MouseEvent):void{ gotoAndStop(3); trace( rbGroup2.selection.value ); so.data["value"] = rbGroup2.selection.value; } // Define and Trace Rb Choice on Button. function back(e:MouseEvent):void{ gotoAndStop(1); trace( rbGroup2.selection.value ); so.data["value"] = rbGroup.selection.value; } // Define Radio Button according to last Click. if ( so.data["value"] == "one month" ) { rbGroup2.selection = rb_7; stage_2_txt.text="one month"; } if ( so.data["value"] == "six months" ) { rbGroup2.selection = rb_8; stage_2_txt.text="six months"; } if ( so.data["value"] == "one year" ) { rbGroup2.selection = rb_9; stage_2_txt.text="one year"; } if ( so.data["value2"] == "two years" ) { rbGroup2.selection = rb_10; stage_2_txt.text="two years"; } if ( so.data["value"] == "three years" ) { rbGroup2.selection = rb_11; stage_2_txt.text="three years"; } if ( so.data["value"] == "four years" ) { rbGroup2.selection = rb_12; stage_2_txt.text="four years"; } If anyone can help point me in the right direction to get this code working? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/187333-storing-radio-button-selections/#findComment-989548 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.