Thursday, May 28, 2009

Reuse ItemRenderers

When dealing with item renderers, one will come across all sorts of problems thrown at . One such case is "how to reuse the same itemrenderer"

Picture this case. You have a custom itemrenderer,( imagine a check box within a canvas for now) that performs a specific task and you want to reuse it on multiple columns. But how will the itemrenderer know which field in the arrayCollection is to be used to render itself appropriately?

Alright. Here is the trick.

There is this interface called IDropInListItemRenderer which your itemrenderer will have to implement to get access to listData which can be typeCasted to DataGridListData. The listData variable will hold reference to the owner of the itemRenderer and the hierarchy upwards. Following is the list of steps one has to follow.

1.Create the itemRenderer class that implements the IDropInListItemRenderer.

2.Create an instance variable to buffer the listData , namely _listData.

3.Override the set/get methods of the listData instance variable . In the setter, buffer the listData onto the instance variable

Following is the complete code

Create the datagrid and use the above created item renderer.
Ex:

The itemRenderer

package
{
import mx.containers.Canvas;
import mx.controls.CheckBox;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;

public class sampleItemRenderer extends Canvas implements IDropInListItemRenderer
{
private var _listData:DataGridListData;
private var _instanceCheckBox:CheckBox = new CheckBox();
private var _currentDataFieldName:String = new String();
public function sampleItemRenderer()
{
super();
}

public function get listData():BaseListData
{
return _listData;
}

public function set listData(value:BaseListData):void
{
_listData = DataGridListData(value);
}
override protected function createChildren():void {
super.createChildren();
addChild(_instanceCheckBox);

}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth,unscaledHeight);
_instanceCheckBox.selected = Boolean(data[_listData.dataField]);
}
}
}











Wednesday, May 27, 2009

About sharedobject

Shared objects function like browser cookies. You use the SharedObject class to store data on the user's local hard disk and call that data during the same session or in a later session. Applications can access only their own SharedObject data, and only if they are running on the same domain. The data is not sent to the server and is not accessible by other Adobe® Flex™ applications running on other domains, but can be made accessible by applications from the same domain.

Shared objects compared with cookies

Cookies and shared objects are very similar. Because most web programmers are familiar with how cookies work, it might be useful to compare cookies and local SharedObjects.

Cookies that adhere to the RFC 2109 standard generally have the following properties:

In contrast, shared objects have the following properties:


Shared object

you want know about third-party local shared objects please refer this site


http://www.adobe.com/products/flashplayer/articles/thirdpartylso/