后来借鉴了下面这个例子,终于意识到是namespace的原因。修改后终于成功:
注意变量定义
[Bindable]
public var availableMarketGroups:ArrayCollection;
引用时的namespace
Application.application.availableMarketGroups
嵌入的import语句
<mx:Script> <![CDATA[ import mx.core.Application; ]]> </mx:Script>
<mx:TitleWindow width="514" height="445" layout="absolute" horizontalAlign="center" verticalAlign="middle" horizontalCenter="0" verticalCenter="-51" fontFamily="Arial" fontSize="12" id="marketGroupAdminPanel" title="Market Group Administration" creationComplete="onGroupAdminWindowCreated(event)"> <mx:DataGrid id="marketGroupList" allowMultipleSelection="true" horizontalScrollPolicy="auto" editable="true" verticalAlign="middle" name="Restricted Market and Group List" textAlign="left" left="59" bottom="29" fontSize="12" fontFamily="Arial" right="68" verticalScrollPolicy="auto" creationComplete="marketGroupListCreationComplete(event)" dataProvider="{getRestrictedMarketGroupInfosResult.lastResult}" itemRollOver="lastRollOverIndex = event.rowIndex" contextMenu="{cmMarketGroupInfoListContextMenu}" top="44" tabIndex="4" > <mx:columns> <mx:DataGridColumn headerText="Market Name" dataField="marketName" editable="false"/> <mx:DataGridColumn headerText="Group Name" dataField="marketGroupName" editable="true" itemEditor="{groupsDropDownComponent}"> <mx:itemRenderer> <mx:Component id="groupsDropDownComponent"> <mx:Box width="100%" height="100%"> <mx:ComboBox dataProvider="{Application.application.availableMarketGroups}" labelField="marketGroupName"> <mx:Script> <![CDATA[ import mx.core.Application; ]]> </mx:Script> </mx:ComboBox> </mx:Box> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn> </mx:columns> </mx:DataGrid> <mx:Button x="58" y="10" label="Create New Market Group" id="createMarketGroup" click="createMarketGroup_clickHandler(event)"/> </mx:TitleWindow>
下面是转载的例子,从网上抓的,原址就不贴了
<?xml version= "1.0 " encoding= "utf-8 "?> <mx:Application xmlns:mx= "http://www.adobe.com/2006/mxml " layout= "absolute " fontFamily= "宋体 " fontSize= "12 " width= "424 " height= "396 "> <mx:Script> <![CDATA[ import mx.controls.*; import mx.core.Application; import mx.controls.dataGridClasses.*; private var DataGrid1:DataGrid [Bindable] public var dataArr2:Array = [{id:1,name: "铅笔 ",price:100,count: "第2次 "}, {id:2,name: "毛笔 ",price:50,count: "第2次 "}, {id:3,name: "钢笔",price:333,count: "第3次 "}] [Bindable] public var dataArr:Array = new Array({label: "第1次 ", data: "1 "},{label: "第2次 ", data: "2 "}, {label: "第3次 ", data: "3 "}, {label: "第4次 ", data: "4 "}); [Bindable] public var s:int = 2; ]]> </mx:Script> <mx:Component id= "myComponent "> <mx:ComboBox x= "179 " y= "1 " width= "67 " dataProvider= "{Application.application.dataArr} " selectedIndex= "{Application.application.s} "> <mx:Script> <![CDATA[ import mx.core.Application; ]]> </mx:Script> </mx:ComboBox> </mx:Component> <mx:DataGrid id= "DataGrid2 " editable= "true " dataProvider= "{Application.application.dataArr2} " y= "200 " x= "10 "> <mx:columns> <mx:DataGridColumn headerText= "序号 " dataField= "id " editable= "false "/> <mx:DataGridColumn headerText= "名称 " dataField= "name "/> <mx:DataGridColumn headerText= "价格 " dataField= "price " editorDataField= "value " editable= "false "> <mx:itemRenderer> <mx:Component> <mx:NumericStepper maximum= "1000 " minimum= "10 "> </mx:NumericStepper> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn> <mx:DataGridColumn headerText= "数量 " dataField= "count " editable= "true " editorDataField= "text " itemEditor= "{myComponent} "/> </mx:columns> </mx:DataGrid> </mx:Application>