tags:

views:

260

answers:

1

I am trying to set the selected value of a checkbox from a dataprovider (an xml file).

<mx:DataGridColumn width="75" headerText="show/hide" dataField="@hidden">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:CheckBox  selected="{data.@hidden}" />
                    </mx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>

The problem I am having is, I think, that it's not recognizing the attribute in the html as boolean "hidden="false" or hidden="true". I can get the value, but how to I make it recognize the value as something other than a string?

A: 

I think you can wrap it in the type {Boolean(data.@hidden)}

An alternative if wrapping it doesn't work you can declare a boolean

var myBool:Boolean = new Boolean();

And then do a determination:

myBool = (data.@hidden=="true");

EDIT I don't have much of your code so I can't really test this but I think it should work.

create an MXML component based on the checkbox with this, for my example it will be called ItemRendCheckBox:

<?xml version="1.0" encoding="utf-8"?>
<mx:CheckBox xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    <mx:Script>
        <![CDATA[
            override public function set data( value:Object ):void{
                super.data = value;
                this.selected = Boolean(data);
            }
        ]]>
    </mx:Script>
</mx:CheckBox>

Then in your dataGrid XML do this:

<mx:DataGridColumn width="75" headerText="show/hide" dataField="@hidden">
  <mx:itemRenderer>
    <mx:Component>
       <mx:ItemRendCheckBox/>
    </mx:Component>
  </mx:itemRenderer>
</mx:DataGridColumn>
invertedSpear
the type didn't work.. where would I do the wrapping? When I create an <mx:Script> and try to trace out data.@hidden, it says it doesn't know what data is. Do I do this in my upperDocument?
pfunc
Check out my edit, not sure what you mean by upperDocument since you really aren't showing me much of your code.
invertedSpear
hmm i must be doing something else wrong, that still didn't work, but good to know how to do that.
pfunc
ok, so it has something to do with the checkbox just not reacting to the value of the boolean value, all the boolean values trace out correctly, but when it comes to unchecking or checking the checkbox, they are all checked off.
pfunc
it's hard to be sure that they are tracing out correctly, remember trace automatically does a toString() method on the item. So a trace(true) = trace("true"); it might be better to put a condition in there: if(myBool=="true"){trace("text true");}else if(myBool == true){trace("boolean true");
invertedSpear
yeah what it is tracing out is the full xmlList for that selected item. although when i try to trace data.@hidden it gives me an error. But for some reason I couldn't do Boolean(data.@hidden). so the conditional works. if(data.@hidden == "true") { this.selected = true; }else { this.selected = false; }Thank you for helping work through this.
pfunc
Glad you got it working
invertedSpear
ok, one morre question on this. I click the checkbox, it gets the write value, I save it to an xml file. When I refresh the dataProvider the checkbox goes back to what it was before, even though it is writing it to the dataprovider. I know this because if I close out the application and then reload it, then the change has been made.It's almost like the customItemRenderer isn't updating when everything else is, unless it reloads. Is there a way to reload a specific element.. in this case the checkbox?
pfunc
You may want to post another question for that particular example. There is, I just don't know what it is, and since our comments are kind of buried now someone who does know the answer probably won't see the question.
invertedSpear