Application.application.selectedItems 是单实例调用吗??
如果我的把这个例子作为一个Compenent(甚至改写成AS)放到其他画面中,而且放了2个这样的Grid,那该如何写呢?
我现在就是在iCheckBox里用不了外面的变量;外面有没法监听到iCheckBox里的事件(不知该 谁.addEventLisenter?)。
两者解决一个就能解决问题。
(我的DataGrid是写在AS里的)-- by TonyLian (2008-12-11 18:02:13)
Application.application.selectedItems只是在main application下的一个变量而已,Application.application是用来访问flex的 Main Application。
你可以直接在你的自定义Grid里写这么一个selectedItems, 那所有的东西就只和这个Grid有关了。
iCheckBox.parent.parent就是那个Grid.
监听Grid的change事件,它会在checkBox的change事件之后触发。或者你可以自己dispatch一个checkBox的删除事件。
private function changeHandle(e:Event):void{
var itemArray:Array = Application.application.selectedItems
this.currentData.action = this.selected.toString()
if(this.selected){
itemArray.push(this.currentData)
}else{
for(var i:int = 0; i<itemArray.length; i++){
if(itemArray[i] == this.currentData){
itemArray.splice(i,1)
}
}
}
(this.parent.parent as DataGrid).dispatchEvent(new MyChecBoxEvent("checBoxClickHandle",this.selected)) }