<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" xmlns:util="cn.isvi.views.util.*" xmlns:stocks="cn.isvi.views.adminStocks.*"> <mx:Metadata> [Event(name="modify",type="flash.events.Event")] </mx:Metadata> <mx:Script> <![CDATA[ import cn.isvi.views.adminStocks.viewRependerer.ButtonRependerer; import mx.controls.AdvancedDataGrid; import cn.isvi.entity.StockInfo; import cn.isvi.entity.Stock; import mx.controls.DataGrid; import mx.controls.Alert; import mx.controls.dataGridClasses.DataGridColumn; import mx.events.ListEvent; import mx.collections.ArrayCollection; import cn.isvi.models.StocksModel; [Bindable] private var sm:StocksModel=StocksModel.getInstance(); //public var testss:String; private var button:ButtonRependerer public function testr():void{ mx.controls.Alert.show("dsafsdafsadfasf"); mx.controls.Alert.show(this.datagird.selectedItem.stockName); } private var sts:ArrayCollection=new ArrayCollection( [ {stockName:"汾酒集团",upanddowns:3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:-3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:-3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:-3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:-3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:-3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:-3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集团",upanddowns:3.5,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00}, {stockName:"汾酒集",upanddowns:3,transfer_quantity:1200,number_of_strands:10000,average_cost:200.00} ] ); import mx.managers.PopUpManager; [Bindable] private var currentStock:Stock; private function test(event:ListEvent):void{ //var data:DataGrid=event.target as DataGrid; // var index:int=event.rowIndex; // var stock:Stock=sm.stocksList.getItemAt(index) as Stock; // // var stock:Stock=data.selectedItem as Stock; // mx.controls.Alert.show("stockName"+stock.stockInfo.averageMonthPrice); // if(!currentStock){ // currentStock=null; // } //this.currentStock=stock; //mx.controls.Alert.show("stock op"+stock.stockInfo.operator); //this.currentState="stockInfomation"; //this.currentState=""; // var si:cn.isvi.views.stocks.stockInfo=new cn.isvi.views.stocks.stockInfo; // si._stock=stock; //si.sig.stock=stock; //si.stock=stock; // PopUpManager.addPopUp(si,this); // PopUpManager.centerPopUp(si); // //// var item:DataGrid=event.target as DataGrid; // Alert.show("zhixing le"); } public function lookInfo():void{ var stock:Stock=datagird.selectedItem as Stock; this.currentStock=stock; this.currentState="stockInfomation"; } public function deleteStock():void{ var stock:Stock=datagird.selectedItem as Stock; //mx.controls.Alert.show("delete stock"); } private function stockNameFunction(item:Object,col:DataGridColumn):String{ return (item as Stock).stockName; } private function upandDownLablefunction(item:Object,col:DataGridColumn):String{ return (item as Stock).upAndDown.toString(); } private function buisnesslabelFunction(item:Object,col:DataGridColumn):String{ return (item as Stock).business.toString(); } private function lookInfoFunction(item:Object,col:DataGridColumn):String{ return ""; } ]]> </mx:Script> <mx:states> <mx:State name="stockInfomation"> <mx:AddChild relativeTo="{stocksInfo}"> <stocks:stockInfo stock="{currentStock}"> </stocks:stockInfo> </mx:AddChild> <mx:RemoveChild target="{datagird}"> </mx:RemoveChild> </mx:State> </mx:states> <mx:VBox id="stocksInfo"> <util:MyDataGrid id="datagird" dataProvider="{sm.stocksList}" doubleClickEnabled="true" editable="true" itemDoubleClick="test(event)"> <util:columns> <mx:DataGridColumn headerText="股票名称" fontStyle="normal" color="green"> <mx:labelFunction> stockNameFunction </mx:labelFunction> </mx:DataGridColumn> <mx:DataGridColumn headerText="涨跌"> <mx:labelFunction> upandDownLablefunction </mx:labelFunction> </mx:DataGridColumn> <mx:DataGridColumn headerText="交易量"> <mx:labelFunction> buisnesslabelFunction </mx:labelFunction> </mx:DataGridColumn> <mx:DataGridColumn headerText="持有股数"> </mx:DataGridColumn> <mx:DataGridColumn headerText="平均成本"> </mx:DataGridColumn> <mx:DataGridColumn headerText="修改" editable="false"> <mx:labelFunction> lookInfoFunction </mx:labelFunction> <mx:itemRenderer> cn.isvi.views.adminStocks.mxmlComponent.ButtonResponder </mx:itemRenderer> </mx:DataGridColumn> <mx:DataGridColumn headerText="查看" editable="false"> <mx:labelFunction> lookInfoFunction </mx:labelFunction> <mx:itemRenderer> <mx:Component> <mx:Button label="查看详细"> <mx:click> <![CDATA[ this.parentDocument.lookInfo(); ]]> </mx:click> </mx:Button> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn> <mx:DataGridColumn editable="false"> <mx:labelFunction> lookInfoFunction </mx:labelFunction> <mx:itemRenderer> <mx:Component> <mx:Button label="删除"> <mx:click> <![CDATA[ this.parentDocument.deleteStock(); ]]> </mx:click> </mx:Button> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn> </util:columns> </util:MyDataGrid> </mx:VBox> <?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"> <mx:Button label="test"> <mx:click> <![CDATA[ Alert.show("test"); test(); ]]> </mx:click> </mx:Button> <mx:Script> <![CDATA[ import mx.controls.Alert; private function test():void{ this.parentDocument.testr(); } ]]> </mx:Script> </mx:Canvas> </mx:Canvas>