[flexcoders] Event broadcasters and listeners with cellRenderers

2006-03-28 Thread nahruka
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

* 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/
 




Re: [flexcoders] Event broadcasters and listeners with cellRenderers

2006-03-28 Thread Omar Ramos



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 [EMAIL PROTECTED] wrote:

Hi all,I'm new at Flex and need some help about event handling amongdifferent 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 dosomething. 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=falsecellRenderer=
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/mxmlinitialize=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:HBoxPlease 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 flexcoders on the web. 
To unsubscribe from this group, send an email to:
[EMAIL PROTECTED] 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 










--
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 "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.