Loading XML in Flash AS3

January 16, 2012

1. Create the xml file, as shown below
2. In the flash file drag a datagrid component from the components panel.
3. Create new instance of the URLLoader class which loads the xml file.
4. xml file is passed to the url inside the URLRequest object.
5. Then add an addEventListener to know when the xml file is completely loaded, we register a COMPLETE event and have it call a function.
In the function we access loaded data through URLLoader ‘s data property.and assign this to XML object.
difference between XMLList and array is that in XMLList length()  is a property.
6. Populate any data driven component including a data grid we have to create an instance of a DataProvider class .
Each time the loop runs xml data is added inside of the griddata provider using addItem({name:value})shorthand notation to create a generic object, name value pairs seperated by a “: ” this data is then set to the datagrid. Freelance flash  developer Bangalore

Loading XML in Flash AS3 code goes here:

var imagesXML:XML;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest(“picts.xml”));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(evt:Event):void
imagesXML = new XML(xmlLoader.data);
var componentProvider:DataProvider = new DataProvider();
for(var i:uint = 0; i < imagesXML.animal.length(); i++)
grid.dataProvider = componentProvider;

grid here is the instance name of datagrid component on stage. Make sure flash has imported
import fl.data.DataProvider;

The xml file is as follows:

<description>bunnies are cute</description></animal>
<description>dogies are lovely</description></animal>
<description>elephant is big</description></animal>
<description>frog is green</description></animal>
<description>butterflies are colorful</description></animal>
<description>kittys are cute</description></animal>


Did you like this post? Please give me a boost, Appreciate your valuable comments, and constructive criticism :-).


Checkbox itemrenderer in datagrid

January 5, 2012

The selected property of the checkbox has to be bounded with the selected property of our entity,  Itemrenderer doesn’t keep track of the selected states correctly this can be fixed by binding data with selected property.Freelance Flash Flex developer India Bangalore

The below code explains the itemrender file called DGCheckBoxEditor

import mx.controls.listClasses.ListData;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.dataGridClasses.DataGridItemRenderer
import mx.events.FlexEvent;

private var _listData:DataGridListData;
// Define a property for returning the new value to the cell.
public var cbSelected:Boolean;

// Implement the drawFocus() method for the VBox.
override public function drawFocus(draw:Boolean):void {

override public function set data(value:Object):void{
super.data = value;

override public function get data():Object {
return super.data;

public function get listData():BaseListData
return _listData;

public function set listData(value:BaseListData):void
_listData = DataGridListData(value);


<mx:CheckBox id=”followUpCB”
change=”cbSelected=followUpCB.selected” paddingLeft=”15″/>

Code to call the itemrender

<mx:DataGrid id=”myGrid”
dataProvider=”{myAC}” editable=”true” >
<mx:DataGridColumn id=”checker” dataField=”FollowUp”
itemRenderer=”DGCheckBoxEditor” rendererIsEditor=”true”
<mx:DataGridColumn id=”checker1″ dataField=”Contact” width=”150″ />
<mx:DataGridColumn dataField=”id” width=”150″ editable=”false”/>