Reputation: 2682
I've got a little question answer app that I've created. Everything is working fine but now I'm trying to make the quiz more dynamic by loading and uploading different quizzes from a database.
I seem to have almost everything working fine but I've ran into a bit of a problem converting my answer check function from static to dynamic data.
Here's a bit of my code.
if (b1.selected != true) {
q1a.styleName = "incorrect";
q1a.text = incorrect + b1.value;
score = score -1;
}
Like a said this seemed to work fine with static content just checking if the radio button was selected or not.
I need to replace - b1.selected with my database variable in this case its pertestq1a.
pertestq1a currently equals b1.
How can I add my variable to this if statement to be recognized as an element id?
Upvotes: 1
Views: 519
Reputation: 1226
Hum I do not write AS3 code anymore but as far as I remember, and if I well understand your database structure (I guess you store the name as a sting) this could help you :
Let: pertestq1a = "b1" you can use the following to retrieve the corresponding display object.
getChildByName(pertestq1a)
So you can use "selected" method this way I guess:
getChildByName(pertestq1a).selected
Indeed, you need to specify a usable "instance name" on the object(s) to use it.
Documentation & examples: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#getChildByName%28%29
Upvotes: 0