?
Solved

AS3 radiobutton validation

Posted on 2009-12-31
6
Medium Priority
?
588 Views
Last Modified: 2012-05-08
I'm building an app where the parent/main mc has a basic navigation structure (just a forward and back button) and all my external/child mc's are composed of questionnaires  where the user is selecting radio buttons.

So say page1 loads and it has several radio button groups.   The user should not be able to advance and load page2 unless all selections have been made.

The only thing I've come up with is to have an ENTER_FRAME event in the page running a function with a looong conditional but there must be a more efficient way to do this.  If done this way, I guess I'd make a custom event so that when all buttons are selected, the "next" button in the parent mc would then let the user proceed to the next page.  Is there a better way to do this?

Here is some sample code I'm working with.
addEventListener(Event.ENTER_FRAME, myFunc);


function myFunc(event:Event):void {
	if ((r1.selected==true||r2.selected==true)&&(r3.selected==true||r4.selected==true)&&(r5.selected==true||r6.selected==true)) {
		trace("you may proceed");
	} else {
		trace("no way jose");
	}
}

Open in new window

0
Comment
Question by:moglie
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:CyanBlue
ID: 26154787
I'd do this...

Create a boolean variable, isSelected, and set it to false initially...
Whenever you click on any radio button, you set the value of the isSelected to true...
When you click on the Next button, check the value of the isSelected to see if it is set to true to proceed or not...

CyanBlue
0
 

Author Comment

by:moglie
ID: 26154891
The thing is I'll have alot of radio button groups.   Each page will have several questions in this kind of format:

How often do you use alcohol?     never, monthly, weekly, daily
How often do you use amphetamines?  never, monthly, weekly, daily
How often do you use sedatives?   never, monthly, weekly, daily

etc. etc.

So a radio button in each group/question has to be selected and then when that criteria is met, user can continue otherwise and message will pop up to complete all question.  Unless I can convince the pm otherwise, there isnt a "submit" type of button I could use for validation so that's why I have to tie it into the navigation
 
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 26155679
I thought that you had 'next' button that will work as a type of a 'submit' button???

When do you exactly advance to the next step???

CyanBlue
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:moglie
ID: 26155722
I guess the "next" button would in effect be submit button as well as a navigation button.  Having trouble with this because it's not like a typical multiple choice style quiz that I've seen examples of where you have one question displayed, make a selection and then go on to the next question.  For this, I have many questions displayed on the same page and a selection has to be made for all questions before then can move on to the next page.
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 total points
ID: 26190013
i agree with CB. Using an onEnterFrame is definately not the most effective way of going about this.

what you can do is create an array, on each page you know there's x number of questions, when a question is answered change the value in the array to 1.
then when you click on the next button first check that all the items in the array are 1, if not you know which ones haven't been checked and you can react accordingly.
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 26323999
Any update???

CyanBlue
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question