当前位置: 代码迷 >> Web前端 >> GataGrid渲染器范例(子程序调用主程序版)
  详细解决方案

GataGrid渲染器范例(子程序调用主程序版)

热度:142   发布时间:2012-11-07 09:56:10.0
GataGrid渲染器实例(子程序调用主程序版)
1、 test.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/halo"
			   minWidth="1024" minHeight="768"
			   creationComplete="init();">
	<fx:Script>
		<![CDATA[
			
			public var testStr:String = "父程序测试属性";    //必须是public的才能被渲染器访问
			public var xmlSource:XML = new XML(<root></root>);
			
			public function init():void{
				for(var i:Number = 0; i < 5; i++){
					xmlSource.appendChild(
									<word>
										<myName>{"薛冲" + i}</myName>
									</word>);  
				}
				dataGridID.dataProvider = xmlSource.word;  
			}
			
			public function parentsMed01(str:String, str2:String):void{    //必须是public的才能被渲染器访问
			    trace(str);
				trace(str2);
			}
			
			public function parentsMed02():void{
				dataGridID.dataProvider = null;
			}
			
		]]>
	</fx:Script>
	
	<mx:Label id="parentsLabelID" x="400" y="10" color="#FF0000" text="我是父程序的Label组件呵呵"
			  click="parentsMed02();"/>
	
	<mx:DataGrid id="dataGridID" x="300" y="50" backgroundColor="#000000" color="#000000">
		<mx:columns>
			<mx:DataGridColumn dataField="myName" headerText="姓名"/>
			<mx:DataGridColumn dataField="" itemRenderer="inButton" headerText="专辑名"/>
		</mx:columns>
	</mx:DataGrid>
	
</s:Application>






2、inButton.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="80" height="30">
	
	<mx:Script>
		<![CDATA[
			[Bindable]
			private var musicMessage:String;
			
			override public function set data(value:Object):void{    //实例化父DataGrid时(此事件)自动执行此方法
				var str:String="";
				super.data = value;    //value就是渲染器所在父组件的数据源的内容
				musicMessage = value["myName"];
			}
			
			private function aa(str:String):void{
				this.parentDocument.parentsLabelID.text = "AAAAA,被渲染器改变了啊---" + str;    //渲染器调用父组件
				trace(this.parentDocument.testStr);    //渲染器调用父属性
				this.parentDocument.testStr = "我是渲染器传过来的";    //渲染器改变父类属性值
			    this.parentDocument.parentsMed01(str, this.parentDocument.testStr);    //渲染器调用父函数
			}
			
		]]>
	</mx:Script>
	
	<mx:Button id="butID" label="{musicMessage}" click="aa(this.data.myName);"/>
	<mx:Label id="labID" x="50" fontSize="12" text="世界"/>
	
</mx:Canvas>

  相关解决方案