MyComponent.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="100%" width="100%">
<mx:Metadata>
[Event( name="addProduct", type="AddProductEvent") ]
</mx:Metadata>
<mx:Script>
<![CDATA[
private function onClikHanlder(e:MouseEvent):void
{
var myEventObj:AddProductEvent = new AddProductEvent( "addProduct", {id:1 ,fistName:"Amit" ,lastName :"Patel"} );
dispatchEvent( myEventObj );
}
]]>
</mx:Script>
<mx:Button id="btn" click="onClikHanlder(event)" label="Click"/>
</mx:Canvas>
AddProductEvent.as
package{
import flash.events.Event;
public class AddProductEvent extends Event {
public var obj:Object;
public function AddProductEvent( type:String, value:Object ) {
super( type );
this.obj = value;
}
override public function clone():Event {
return new AddProductEvent( type, obj );
}
}
}
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.DataGrid;
import mx.controls.Alert;
import AddProductEvent;
private function onAddProduct( event:AddProductEvent):void {
var dg:DataGrid = new DataGrid();
dg.dataProvider = event.obj;
addChild(dg);
}
]]>
</mx:Script>
<local:MyComponent id="myComponent" addProduct="onAddProduct( event );"/>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="100%" width="100%">
<mx:Metadata>
[Event( name="addProduct", type="AddProductEvent") ]
</mx:Metadata>
<mx:Script>
<![CDATA[
private function onClikHanlder(e:MouseEvent):void
{
var myEventObj:AddProductEvent = new AddProductEvent( "addProduct", {id:1 ,fistName:"Amit" ,lastName :"Patel"} );
dispatchEvent( myEventObj );
}
]]>
</mx:Script>
<mx:Button id="btn" click="onClikHanlder(event)" label="Click"/>
</mx:Canvas>
AddProductEvent.as
package{
import flash.events.Event;
public class AddProductEvent extends Event {
public var obj:Object;
public function AddProductEvent( type:String, value:Object ) {
super( type );
this.obj = value;
}
override public function clone():Event {
return new AddProductEvent( type, obj );
}
}
}
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.DataGrid;
import mx.controls.Alert;
import AddProductEvent;
private function onAddProduct( event:AddProductEvent):void {
var dg:DataGrid = new DataGrid();
dg.dataProvider = event.obj;
addChild(dg);
}
]]>
</mx:Script>
<local:MyComponent id="myComponent" addProduct="onAddProduct( event );"/>
</mx:Application>
No comments:
Post a Comment