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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值