Link to home
Start Free TrialLog in
Avatar of somnamblst
somnamblst

asked on

AS2: Retrieve which of 3 radio buttons is selected

I have a Flash file with a working poll that calculates the percentage of "votes" once the submit button is clicked. It uses a 3rd party AII that allows additional Flash files to be launched with the function myPR.openPanel();

I am also attempting to  determine which of the 3 radio buttons are selected in order to open 1 of 3 SWFs identified as panel 1, 2 or 3.

I have been searching for information on radio button components, however the radio buttons in this movie are not Flash component radio buttons.

Once the selection is determined, I need the function myPR.openPanel(1); myPR.openPanel(2); or myPR.openPanel(3);assigned to the 3 possible selections and executed when pr_submitBtn is clicked .

AS below, FLA attached.


// This file demonstrates how polling functionality can be implemented

// Import Pointroll API
import PointRollAPI.PointRoll;

// Create new PointRoll instance
var myPR:PointRoll = new PointRoll(this);


// Loading new vars
var result_lv:LoadVars = new LoadVars();

// Radio buttons code
radioBtns_mc.pr_option1.onPress = function():Void  {
      myPR.activity(1, true);
      this.gotoAndStop(2);
      radioBtns_mc.pr_option2.gotoAndStop(1);
      // Pointroll Option 1 Link
      optionLink="http://clk.pointroll.com/polling/?survey=2707955&decimal=2&Q1=1";
      trace("Option 1 selected");
};

radioBtns_mc.pr_option2.onPress = function():Void  {
      myPR.activity(2, true);
      this.gotoAndStop(2);
      radioBtns_mc.pr_option1.gotoAndStop(1);
      // Pointroll Option 2 Link
      optionLink="http://clk.pointroll.com/polling/?survey=2707955&decimal=2&Q1=2";
      trace("Option 2 selected");
};

radioBtns_mc.pr_option3.onPress = function():Void  {
      myPR.activity(3, true);
      this.gotoAndStop(2);
      radioBtns_mc.pr_option1.gotoAndStop(1);
      // Pointroll Option 3 Link
      optionLink="http://clk.pointroll.com/polling/?survey=2707955&decimal=2&Q1=3";
      trace("Option 3 selected");
};


// Submit poll input and open panels one of three
pr_submitBtn.onRelease = function():Void  {

      // Load URL, and display poll results on load
      result_lv.load(optionLink);
      result_lv.onLoad = function() {
            pollResults();
      };
      
            
      // Sets activity for submit
      myPR.activity(myPR.activityID.Polling.SUBMIT);
      trace("Poll submitted");
      
            
radioBtns_mc._visible = false;
      pr_submitBtn._visible = false;
      pr_replayBtn._visible = true;
      // Header will say "Polling Results"
      textHeader(2);
};

//BEGIN MY AS TO GET THE VALUE OF SELECTED RADIO BUTTON

my_vars.radioBtns_mc = radioBtns_mc.selected;
my_vars.selectedRadio = radioBtns_mc.selection;
my_vars.selectedData = radioBtns_mc.selection.data;

radioListener = new Object();
radioListener.click = function(evt) {
    my_vars.selectedData = evt.target.selection.data;
}
radioGroup.addEventListener("onClick", radioListener);

// launch one of three panels depending on selection

pr_submitBtn.click = function(){

//pr_submitBtn.setClickHandler("onClick");

if (radioBtns_mc.pr_option1 == selected)
      trace("one is selected");

      {_parent.myPR.openPanel(1); }

if (radioBtns_mc.pr_option2 == selected)
      trace("two is selected");
      {_parent.myPR.openPanel(2);}

if (radioBtns_mc.pr_option3 == selected)
      trace("three is selected");
   {_parent.myPR.openPanel(3); }
   
};

//END
      
// Replay poll
pr_replayBtn.onRelease = function()
{
      //
      myPR.activity(3, true);
      visiblePollBtns();
      this._visible = false;
      result_lv.unload(optionLink);
      // Show option as selected
      radioBtns_mc.pr_option1.gotoAndStop(1);

      radioBtns_mc.pr_option2.gotoAndStop(1);

      radioBtns_mc.pr_option3.gotoAndStop(1);
      
      // Clear displayed results
      result1.text = "";
      result2.text = "";
      result3.text = "";
      // Header will say "Choose Option"
      textHeader(1);
      trace("Replay button selected");
};

// Will display results of poll input
function pollResults() {
      var option1 = result_lv.Q1A1 + "%";
      var option2 = result_lv.Q1A2 + "%";
      var option3 = result_lv.Q1A3 + "%";
      result1.text = option1;
      result2.text = option2;
      result3.text = option3;
      trace("Option1 ="+" "+option1);
      trace("Option2 ="+" "+option2);
      trace("Option3 ="+" "+option3);
      }
      
function visiblePollBtns() {
      txtMC._visible = true;
      radioBtns_mc._visible = true;
      pr_submitBtn._visible = true;
}

function hidePollBtns() {
      txtMC._visible = false;
      radioBtns_mc._visible = false;
      pr_submitBtn._visible = false;
      pr_replayBtn._visible = false;
}

// Handles what this textfield will display
function textHeader(header:Number) {
      if (header == 1) {
            txtMC.polling_instructions.text = "Choose Your Favorite";
      } else {
            txtMC.polling_instructions.text = "The Favorites Are:";
      }
}

frischs-PR-300x250-poll-v3.fla
Avatar of moagrius
moagrius
Flag of United States of America image

the obvious answer to me would is to just save the selection in a variable.

somewhere outside function code, put:

var selectedOption:int = -1;

then in the radio button click handlers, set the selectedOption:

radioBtns_mc.pr_option1.onPress = function():Void  {
      myPR.activity(1, true);
      this.gotoAndStop(2);
      radioBtns_mc.pr_option2.gotoAndStop(1);
      // Pointroll Option 1 Link
      optionLink="http://clk.pointroll.com/polling/?survey=2707955&decimal=2&Q1=1";
      trace("Option 1 selected");
      // set the selectedOption variable
      selectedOption = 1;
};

(repeat that for the other radio button handlers)

then in the pr_submitBtn release handler, call the function on the selectedOption:

pr_submitBtn.onRelease = function():Void  {

      // Load URL, and display poll results on load
      result_lv.load(optionLink);
      result_lv.onLoad = function() {
            pollResults();
      };
     
           
      // Sets activity for submit
      myPR.activity(myPR.activityID.Polling.SUBMIT);
      trace("Poll submitted");
     
           
      radioBtns_mc._visible = false;
      pr_submitBtn._visible = false;
      pr_replayBtn._visible = true;
      // Header will say "Polling Results"
      textHeader(2);

      // call the openPanel method on the selectedOption, if an option has been selected
      if(selectedOption > -1) myPR.openPanel(selectedOption);
};


Avatar of somnamblst
somnamblst

ASKER

I am getting one compiler error for this variable: var selectedOption:int = -1;

The class or interface 'int' could not be loaded.

Is int AS3 only?

ASKER CERTIFIED SOLUTION
Avatar of moagrius
moagrius
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial