You can catch the event this way:
?xml version=1.0 encoding=utf-8?
mx:HBox xmlns:mx=http://www.macromedia.com/2003/mxml;
creationComplete=inici() hScrollPolicy=off
mx:Script![CDATA[
public var listOwner: mx.controls.List;
function inici(): Void {
listOwner.parentDocument.addEventListener(myEvent,
mx.utils.Delegate.create(this, btnClicked));
}
function btnClicked(): Void {
mx.controls.Alert.show(myEvent caught);
}
]]/mx:Script
!-- Several Flex components go here --
/mx:HBox
Note that this will trigger the function for every row displayed,
even if the row is empty. I'm not sure if this is really what you
want. It might be a better idea to just have the event handled by
the datagrid instead of the cell renderer, so that you can loop
through the data.
Hope that helps,
Doug
--- In flexcoders@yahoogroups.com, nahruka [EMAIL PROTECTED] wrote:
Thank you Omar, I tried your approach but it didn't work... I'll
keep
on trying :-S
--- In flexcoders@yahoogroups.com, Omar Ramos flex.list@ wrote:
Hi,
On your cell render you can use these properties.
public var listOwner:mx.controls.List;
private var getCellIndex:Function;
private var getDataLabel:Function;
So instead of using parent use listOwner.parent, that should
give you
access to your button. Another aproach is to dispatch the button
event into
the TileList and then on your cellrender listen to it using
listOwner.addEventListener(myEvent). Let me know if this was of
any help.
Omar Ramos
On 3/28/06, nahruka curaeweb@ wrote:
Hi all,
I'm new at Flex and need some help about event handling among
different Flex components. I have a custom TitleWindow with a
Button.
I want another custom component (used as a cell renderer in
this
TitleWindow) to listen to this button to be clicked and then do
something.
Here is my TitleWindow WActes.mxml:
?xml version=1.0 encoding=utf-8?
mx:TitleWindow xmlns:mx=http://www.macromedia.com/2003/mxml;
xmlns=* xmlns:ns1=Components.*
creationComplete=doInit()
title=This is my popup closeButton=true
click=this.deletePopUp()
mx:Metadata
[Event(myEvent)]
/mx:Metadata
mx:Script![CDATA[
function myButtonClick() {
dispatchEvent({type:myEvent});
}
]]/mx:Script
mx:DataGrid id=dgAlu dataProvider={myArr} width=100%
height=100% editable=true
variableRowHeight=true wordWrap=true
mx:columns
mx:Array
mx:DataGridColumn headerText=Nom columnName=nom
editable=false width=80
wordWrap=true/mx:DataGridColumn
mx:DataGridColumn headerText=Qualificacio
editable=false
cellRenderer=Components.HBoxQualificacio/mx:DataGridColumn
/mx:Array
/mx:columns
/mx:DataGrid
mx:ControlBar
mx:Button label=Close click=deletePopUp()/
mx:Button id=myButton label=Click here
click=myButtonClick()/mx:Button
/mx:ControlBar
/mx:TitleWindow
And here is my own cell renderer, HBoxQualificacio.mxml:
?xml version=1.0 encoding=utf-8?
mx:HBox xmlns:mx=http://www.macromedia.com/2003/mxml;
initialize=inici() hScrollPolicy=off
mx:Script![CDATA[
function inici() {
var listenerObject = new Object();
listenerObject.myEvent = function(event) {
trace(myEvent catched); //This is never printed!!! :-(
}
parent.myButton.addEventListener(myEvent,
listenerObject);
}
]]/mx:Script
!-- Several Flex components go here --
/mx:HBox
Please I do need some help! Thanks!
--
Flexcoders Mailing List
FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
--
YAHOO! GROUPS LINKS
- Visit your group
flexcodershttp://groups.yahoo.com/group/flexcoders
on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]flexcoders-
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms
of
Service http://docs.yahoo.com/info/terms/.
--
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/