Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Extensions and Plugins > Components

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-24-2009, 04:20 PM   #1
somnamblst
Member
 
Join Date: Aug 2007
Posts: 41
Question [AS2] Check which radio btn was selected in poll

I have a poll that on submit also launchs a 2nd SWF on submit. Everything works, except I want to launch one of three separate SWFs based on which option is selected, either radioBtns_mc.pr_option1, radioBtns_mc.pr_option2 or radioBtns_mc.pr_option3.

I think I am close but can't figure out how to check which option was selected.

Code:
// 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);
	//_root.myPR.openPanel(1);
	//_root.myPR.pin(1);
	
	// launch one of three panels depending on selection
	
			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);
            }
	
};
Complete AS

Code:
// 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);
	//_root.myPR.openPanel(1);
	//_root.myPR.pin(1);
	
	// launch one of three panels depending on selection
	
			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);
            }
	
};






// 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);
	}
	
/*	import PointRollAPI.data.DataStorage;
	
if (pr_option1 == true) {
    DataStorage.setVariable("whichFrame", "one");
   _parent.myPR.openPanel(1); //(you really shouldn’t use _root)
} else if (pr_option2 == true) {
    DataStorage.setVariable("whichFrame", "two");
       _parent.myPR.openPanel(1);
} else if (pr_option3 == true) {
    DataStorage.setVariable("whichFrame", "three");
        _parent.myPR.openPanel(1);
}*/

 


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:";
	}
}
somnamblst is offline   Reply With Quote
Old 12-24-2009, 05:06 PM   #2
somnamblst
Member
 
Join Date: Aug 2007
Posts: 41
Default Sorry moderator, I did not think this was a components question....

because the "radio btns" are just buttons that are part of the 3rd party API, not Flash component radio buttons with accessible parameters.
somnamblst is offline   Reply With Quote
Old 12-27-2009, 01:40 PM   #3
somnamblst
Member
 
Join Date: Aug 2007
Posts: 41
Default I think I am much closer

I think I need to obtain the value of which of the radio buttons in radioBtns_mc was selected. I feel like there is just something simple I am missing. My added code is in bold

Code:
// 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);
};


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.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); }
	
// 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:";
	}
}
somnamblst is offline   Reply With Quote
Old 12-30-2009, 06:11 AM   #4
caseyctg
Senior Member
 
Join Date: Apr 2005
Location: st louis, MO
Posts: 160
Default See the example give from adobe

ActionScript Code:
import fl.controls.RadioButton; import fl.controls.RadioButtonGroup; var rbg1:RadioButtonGroup = new RadioButtonGroup("group1"); var rbg2:RadioButtonGroup = new RadioButtonGroup("group2"); var rb1:RadioButton = new RadioButton(); var rb2:RadioButton = new RadioButton(); var rb3:RadioButton = new RadioButton(); var rb4:RadioButton = new RadioButton(); rb1.addEventListener(MouseEvent.CLICK, announceGroup); rb2.addEventListener(MouseEvent.CLICK, announceGroup); rb3.addEventListener(MouseEvent.CLICK, announceGroup); rb4.addEventListener(MouseEvent.CLICK, announceGroup); rb1.group = rb2.group = rbg1; rb3.group = rb4.group = rbg2; rb1.move(10,10); rb2.move(10,50); rb3.move(150,10); rb4.move(150,50); addChild(rb1); addChild(rb2); addChild(rb3); addChild(rb4); function announceGroup(e:MouseEvent):void {     var rb:RadioButton = e.target as RadioButton;     trace(rb.groupName); }
caseyctg is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:36 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.