tags:

views:

126

answers:

2

Since Repeater component won't generate radiobuttongroup in mxml, and since I can't do the same through ActionScript because radiobuttongroup doesn't have an id property when I try to create it that way, is there a way to disable radiobuttons at all? As far as I can see, the only thing I can set and access is groupName property of radiobuttons.

For Repeater component I tried using xml directly

<mx:XML id="xquiz" source="quiz.xml" />

with this code:

<mx:Repeater dataProvider="{xquiz.question}" id="rep">
        <mx:Label text="{rep.currentItem.content}" />
        <mx:Repeater dataProvider="{rep.currentItem.answer}" id="rep2">
            <mx:RadioButton label="{rep2.currentItem}" groupName="{'rbg'+rep.currentIndex}" click="checkAnswers(event)" value="{rep2.currentItem.@correct}" />
        </mx:Repeater>
    </mx:Repeater>

and cannot use repeater to generate radiobuttongroup since it's not a visible component.

I also tried ActionScript approach but with HTTPService mxml component to fetch xml file.

<mx:HTTPService id="srv" url="quiz.xml" resultFormat="e4x" result="handleResult(event);" fault="handleFault(event);"/>

and here's actionscript snippet:

private var xQuizData:XML

private function handleResult(event:ResultEvent):void {
                xQuizData = event.result as XML;
                initApp();
            }

private function initApp():void {
                var cnt:Number = 0;
                for each (var question:XML in xQuizData.*) {
                    var lbl:Label = new Label();
                    lbl.text = question.content;
                    panel.addChild(lbl);
                    lbl.visible = true;
                    var cnt2:Number = 0;
                    for each (var answer:XML in question.answer) {
                        var rb:RadioButton = new RadioButton();
                        rb.id=String(cnt);
                        rb.label=answer;
                        rb.groupName="rbg"+String(cnt);
                        if (answer.hasOwnProperty("correct")) {
                            rb.value=true;
                        }
                        panel.addChild(rb);
                        rb.visible = true;
                        cnt2++;
                    }
                    cnt++;
                }
            }

I want to be able to catch clicks from radiobuttongroup controls, but can't get them to generate at all if with repeater or can't assign them id if with actionscript.

XML contents would look something like this:

<quiz>
<question>
<content>Some question?</content>
<answer>Answer one</answer>
<answer correct="true">Answer two</answer>
<answer>Answer three</answer>
<answer>Answer four</answer>
</question>
</quiz>
A: 

I'm having a hard time following what you are trying to do from your snippets, so here's a snippet of mine that should do exactly what your wanting. Hopefully you can review it and adapt it for your problem.

public function buildVBox():void{
    tempVBox.removeAllChildren();
    var iterator:Number = 0;

    for each (var i:XML in myXML.children()){

        var tempCanv:Canvas = new Canvas();
        tempCanv.id = iterator.toString();
        var tempRadYes:RadioButton = new RadioButton;
        tempRadYes.x = 30; 
        tempRadYes.y = 20;
        tempRadYes.origY = 20;
        tempRadYes.groupName = "rbg" + iterator.toString();
        tempRadYes.value = 1; 
        tempRadYes.label = "Yes"
        tempCanv.addChild(tempRadYes);
        var tempRadNo:extRadioButton = new extRadioButton;
        tempRadNo.x = 80; 
        tempRadNo.y = 20;
        tempRadNo.origY = 20;
        tempRadNo.groupName = "rbg" + iterator.toString();
        tempRadNo.value = 2; 
        tempRadNo.label = "No"
        tempCanv.addChild(tempRadNo);
        var tempRadNA:extRadioButton = new extRadioButton;
        tempRadNA.x = 120; 
        tempRadNA.y = 20;
        tempRadNA.origY = 20;
        tempRadNA.groupName = "rbg" + iterator.toString();
        tempRadNA.value = 0; tempRadNA.label = "N/A"
        tempCanv.addChild(tempRadNA);
        tempVBox.addChild(tempCanv);
        iterator++;
    }
}
invertedSpear
You're doing the same thing I'm doing. I have no problem grouping radiobuttons, but with accessing specific group in order to trigger an event on all buttons at once, check if the clicked answer is correct and disable the entire group. The difference is in radiobutton property "groupName" and "group". I need to use "group" property but can't get it to work with dynamically created radiobuttongroup controls. :(
Lats
found solution here: http://www.jonathanrowny.com/journal/radiobuttongroup-inside-repeater
Lats
A: 

Got a solution from here: http://www.jonathanrowny.com/journal/radiobuttongroup-inside-repeater

Lats