SpriteCellRenderer class
/******************************************************************************
SpriteCellRenderer class
copyright Flashscript.biz: 2010
CellRenderer class for the DataGrid example.
********************************************************************************/
package
{
import flash.display.Sprite;
import flash.display.DisplayObject;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
import flash.utils.getDefinitionByName;
import flash.events.Event;
/*
* Extending the Sprite class will give this class all the properties and
* methods of the Sprite class. We need to add, however, all the functions
* of the ICellRenderer class, since the Sprite class does not have any of
* these functions.
*/
public class SpriteCellRenderer extends Sprite implements ICellRenderer
{
protected var _data:Object;
protected var _listData:ListData;
protected var _selected:Boolean;
private var wasSelected:Boolean = false;
public function SpriteCellRenderer ():void
{
super ();
}
public function setSize (width:Number,height:Number):void
{
}
public function setStyle (style:String, value:Object):void
{
}
public function get data ():Object
{
return _data;
}
/*
* We get here the data from the Document class, when the items are added to the
* DataGrid. Since this function is triggered not only when the movie opens but
* also when the user clicks on a row, we need to make sure that we inactivate
* this function as soon as all the instances of the MovieClip have been placed.
*/
public function set data (value:Object):void
{
_data = value;
if (!wasSelected)
{
var ClassReference:Class = getDefinitionByName(_data.data) as Class;
var instance:Object = new ClassReference();
addChild (DisplayObject(instance));
wasSelected = true;
}
}
public function get listData ():ListData
{
return _listData;
}
public function set listData (value:ListData):void
{
_listData = value;
}
public function get selected ():Boolean
{
return _selected;
}
public function set selected (value:Boolean):void
{
_selected = value;
}
public function setMouseState (state:String):void
{
}
}
}