Link to home
Start Free TrialLog in
Avatar of ximenao
ximenao

asked on

Simple Question about Radio Buttons in Flash

Hello,I seem to be having trouble using radio buttons with Flash and as 2.
Here is the problem. I am currently coding an exam entirely in Adobe Flash. It is a simple multiple choice exam, where there are four choices underneath each question. When the user selects the right answer, a point is added to the dynamic textbox with the variable name " total". At this point it should be added that the answers will only be selected when the user clicks on a radio button, they will be added to the textox when he/she clicks the submit button (where the actionscript code is). Please check the code attached to see what I have so far. I have successfully created this same kind of exam online with PHP and MySQL but seem to have trouble migrating to Flash. Whenever I use the code below, I get the several syntax errors.

Can anyone tell me where I wrong?
on (release) {
    if (q1.getValue()=="4") {
	_root.total = _root.total + 100;
    }
else {
	_root.total = _root.total + 0;
    }

    if (q2.getValue()=="18") {
	_root.total = _root.total + 100;;
    } else {
	_root.total = _root.total + 0;
    }
}
        _root.total = _root.total + 100 ;

Open in new window

Avatar of blue-genie
blue-genie
Flag of South Africa image

i'm not sure what your question is, but in terms of the syntax issues it will be much easier if you tell us specifically what the errors are.

but the obvious thing that jumps out.

1. i'm assuming this code in in the button actions  and NOT timeline / frame - otherwise it will throw an error.
2. the last line of code _root.total = _root.total + 100; is hanging around out of place, it should be in the on(release) code block as well.
3. does getValue() return strings?

4. not an error just a short cut

_root.total += 10; is the same as _root.total = _root.total + 10; //just less typing
Avatar of ximenao
ximenao

ASKER

Thanks for responding blue-genie, and for the tip.
Looking at the code I posted I realize that I made an error in posting; the final line _root.total = _root.total + 100; was posted by accident. The actual code is everything above it.
And whenever I use that code, I get the following errors:

frarSyntax error.
Avatar of ximenao

ASKER

Sorry, here the errors I get:
Syntax error—if (q1.getValue()=="b") {
Avatar of ximenao

ASKER

Having some difficulty posting these errors. Here are the rest, attached as code.

And the getValue() is meant to return a string.
Statement must appear within on handler—_root.total = _root.total + 100;
Syntax error—} else {

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of andreMariano
andreMariano
Flag of Brazil 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
I'm just going to follow on from my thread and train of thought here so if what andreMariano says conflicts with what I'm saying - pick one route.

statement must appear within on handler—_root.total = _root.total + 100 - that is the error i was referring to where that last line must appear within the statement, which you said it shouldnt' so if you delete that then that error should fall away.

you are attaching the code to the movieclip and NOT to the timeline right?


would be easier if you could upload your file if you're still getting errors after this.
Avatar of ximenao

ASKER

Thank both of you for all your help.... the code works perfectly now.