Search code examples
flashactionscriptdatagriddataprovider

Flash DataGrid DataProvider Manipulation


Posting for a colleague. Please don't up-vote or down-vote.

This is all inside the same MXML file.

public function toggleMonitor(part:Object):void { 
    if(part.active == 0)
        part.active = 1;
    else
        part.active = 0;
}

public function monitorAll(monitor:int):void {
    for(var part:Object in blah) {
        part.active = monitor;
    }
}

<mx:DataGrid dataProvider="{blah}">
    <mx:columns>
        <mx:DataGridColumn>
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Image source="{data.active == 0 ? img1 : img2}" click="outerDocument.toggleMonitor(data)"/>
                </mx:Component>
            </mx:itemRenderer>  
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>

<mx:Button click="monitorAll(1)"/>

Clicking on the image correct toggles the image (i.e. the toggleMonitor function works). But clicking on the button doesn't (i.e. the monitorAll function does not work). Why isn't the button working?


Solution

  • He managed to work out the issue. The method should be like this:

    public function monitorAll(monitor:int):void {
        blah.refresh(); 
            for (var i:int = 0; i < blah.length; i++){
                (blah.getItemAt(i) as Object).active = monitor; 
            }
        blah.refresh(); 
    }