效果:http://up.qzone.net.cn/qzone.net.cn/20080811032030_a.swf
组件运用创建 DataGrid 实例并侦听其事件
步骤:1.将 DataGrid 组件添加到库中。 2.将该代码作为 DataGridExample.as 另存到 FLA 文件所在的同一目录中。 3.将 FLA 文件中的 Document 类设置为 DataGridExample。
代码:package {import flash.display.Sprite;import flash.events.Event;import fl.data.DataProvider;import fl.events.DataGridEvent;import fl.controls.DataGrid;import flash.text.TextField;import flash.text.TextFieldAutoSize;
public class DataGridExample extends Sprite { var tfn:TextField; var tfnu:TextField; var tfe:TextField; var dp:DataProvider; var dg:DataGrid;
public function DataGridExample() { creatdg(); creattf();
} function creatdg() { dp=new DataProvider(); dp.addItem({Name:"John Alpha",Number:"555-123-0101",Email:"jalpha@fictitious.com"}); dp.addItem({Name:"Mary Bravo",Number:"555-372-3322",Email:"mbravo@fictitious.com"}); dp.addItem({Name:"Trevor Gamma",Number:"555-485-1212",Email:"tgamma@fictitious.com"}); dg=new DataGrid(); dg.move(10, 10); dg.width = 500; dg.rowCount = 3;
dg.columns=["Name","Number","Email"]; dg.dataProvider=dp; addChild(dg); dg.addEventListener(Event.CHANGE,grid); } function creattf() { tfn=new TextField(); tfn.x=10; tfn.y=100; addChild(tfn); tfnu=new TextField(); tfnu.x=10; tfnu.y=115; addChild(tfnu); tfe=new TextField(); tfe.x=10; tfe.y=130; addChild(tfe); tfn.autoSize = TextFieldAutoSize.LEFT; tfnu.autoSize = TextFieldAutoSize.LEFT; tfe.autoSize = TextFieldAutoSize.LEFT;
} function grid(e:Event):void {
tfn.text="Name:"+e.target.selectedItem.Name; tfnu.text="Number:"+e.target.selectedItem.Number; tfe.text="Email:"+e.target.selectedItem.Email; }}}
没有评论:
发表评论