-
在flash as3中的 datagrid中放入其它组件 - [flash学习笔记]2009-04-29
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://crazyrabbit.blogbus.com/logs/38679206.html
大家都知道在flash as3中使用datagrid显示数据比较方便,但是怎么在datagrid中怎么插入其他组件呢,
本人谷歌了好长时间终于在官方网站中找到了这么一篇文章
大致是在datagrid的一个单元格中用uiloader组件显示图片,
// Import the required component classes.
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
/* Create and populate a new DataProvider object. Note that three of the items
in the data provider refer to externally-loaded images, whereas the last two
items refer to symbol linkages in the library. */
var dp:DataProvider = new DataProvider();
dp.addItem({data:"http://www.helpexamples.com/flash/images/image1.jpg", title:"image1.jpg"});
dp.addItem({data:"http://www.helpexamples.com/flash/images/image2.jpg", title:"image2.jpg"});
dp.addItem({data:"http://www.helpexamples.com/flash/images/image3.jpg", title:"image3.jpg"});
dp.addItem({data:"Bear", title:"Bear.jpg"});
dp.addItem({data:"Lion", title:"Lion.jpg"});
// Create a new DataGridColumn object, and specify a custom cell renderer.
var dataCol:DataGridColumn = new DataGridColumn("data");
dataCol.cellRenderer = LoaderCellRenderer;
// Create a new DataGridColumn object.
var titleCol:DataGridColumn = new DataGridColumn("title");
/* Create a new DataGrid component instance, add the two DataGridColumn
objects created earlier, define the data provider and add the instance
to the display list. */
var myDataGrid:DataGrid = new DataGrid();
myDataGrid.addColumn(dataCol);
myDataGrid.addColumn(titleCol);
myDataGrid.dataProvider = dp;
myDataGrid.rowHeight = 64;
myDataGrid.width = 200;
myDataGrid.rowCount = dp.length - 1;
myDataGrid.move(10, 10);
addChild(myDataGrid);LoaderCellRenderer类:
package {
// Import the required component classes.
import fl.containers.UILoader;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
import fl.core.InvalidationType;
import fl.data.DataProvider;
import flash.events.Event;
/**
* This class creates a custom cell renderer which displays an image in a cell.
* Make sure the class is marked "public" and in the case of our custom cell renderer,
* extends the UILoader class and implements the ICellRenderer interface.
*/
public class LoaderCellRenderer extends UILoader implements ICellRenderer {
protected var _data:Object;
protected var _listData:ListData;
protected var _selected:Boolean;
/**
* Constructor.
*/
public function LoaderCellRenderer():void {
super();
}
/**
* Gets or sets the cell's internal _data property.
*/
public function get data():Object {
return _data;
}
/**
* @private (setter)
*/
public function set data(value:Object):void {
_data = value;
source = value.data;
}
/**
* Gets or sets the cell's internal _listData property.
*/
public function get listData():ListData {
return _listData;
}
/**
* @private (setter)
*/
public function set listData(value:ListData):void {
_listData = value;
invalidate(InvalidationType.DATA);
invalidate(InvalidationType.STATE);
}
/**
* Gets or sets the cell's internal _selected property.
*/
public function get selected():Boolean {
return _selected;
}
/**
* @private (setter)
*/
public function set selected(value:Boolean):void {
_selected = value;
invalidate(InvalidationType.STATE);
}
/**
* Sets the internal mouse state.
*/
public function setMouseState(state:String):void {
}
}
}
随机文章:
学习AS3菜鸟起飞吧之—事件处理 转载 2009-12-16flash 接口 2009-04-29FLASH制作全套装备(强烈推荐下载)(转) 2008-09-27flash as3 数组的拷贝 2008-09-04如何将外部xml作为DataGrid 的数据源 2008-03-26
收藏到:Del.icio.us







