Being new to flex, I'm not sure if this is the best solution, but this is the
workaround I came up with:
In the main mxml file:
[Bindable] private var dbt1:ClassFactory = new ClassFactory(
GenericButtonItemRenderer );
// in an init function of your choice
dbt1.properties = { iconSource: deleteIcon, caption: "", callback: deleteRow };
public function deleteRow( row:XML ):void{
}
..in the DataGrid, my column looks like this:
<mx:DataGridColumn headerText="delete" textAlign="center" editable="false"
itemRenderer="{dbt1}" />
Here's the GenericButtonItemRenderer I drummed up:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"
horizontalAlign="center" implements="mx.core.IFactory">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
[Bindable] public var iconSource:Class;
[Bindable] public var caption:String;
public var callback:Function;
public function newInstance():*{
return new GenericButtonItemRenderer();
}
override public function set data(value:Object):void {
if( value != null ){
super.data = value;
}
}
private function onClick(e:MouseEvent) : void {
callback( super.data );
}
]]>
</mx:Script>
<mx:Button click="onClick(event)" label="{caption}" icon="{iconSource}" />
</mx:HBox>
HTH
Alex
----- Original Message -----
From: Ravi Kumar Gummadi
To: [email protected]
Sent: Tuesday, March 13, 2007 1:22 AM
Subject: RE: [flexcoders] Need a hand with a scope problem
Have the function placed in the script section of parentDocument a.l.a the
document which contains this mxml file or the parentApplication a.l.a the
Application tag which contains the whole app.
<mx:Button label="" icon="@Embed('../images/delete.png')"
click="parentDocument.deleteRow( data.tld );" />
<mx:Button label="" icon="@Embed('../images/delete.png')"
click="parentApplication.deleteRow( data.tld );" />
Even I faced the same problem, If anyone can suggest a way to access the
code placed in the same mxml file, it would be really helpful
Hope this helps,
Cheers,
Ravi Gummadi
PartyGaming Plc
------------------------------------------------------------------------------
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of
Alexandre Lemaire
Sent: Tuesday, March 13, 2007 10:44 AM
To: [email protected]
Subject: [flexcoders] Need a hand with a scope problem
Inside of an mxml file, I have a datagrid, with a Button item renderer as
such:
<mx:DataGridColumn
headerText="delete" textAlign="center" editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:VBox horizontalAlign="center">
<mx:Button label="" icon="@Embed('../images/delete.png')" />
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
In that Button, I would like to call a function that exists in the same .mxml
file
public function deleteRow( id:String ):void{
}
Unfortunately, if I edit the button to read like:
<mx:Button label="" icon="@Embed('../images/delete.png')" click="deleteRow(
data.tld );" />
It writes that the function deleteRow doesn't exist, which I imagine is a
scope problem. How do I get around this?
Thanks in advance,
Alex