Hi,
i dispatch from itemrenderers to parent list like this:
(owner as List).dispatchEvent(myEvent);
handling custom events with mxml is more complicated. you could listen
for the list creation complete event (in mxml) and then add listeners
for the itemrenderer events via AS3, eg:
<s:List id="myList" creationComplete="initList" />
function initList():void
{
myList.addEventListener(....);
}
On 11/10/2013 16:23, Thomas Wright wrote:
So - now, after attempting to add some event handlers here, I remember why
I did what I did.
How on earth do you dispatch events from itemrenderers, and successfully
add handlers dynamically to the view?
First off, the mxml for the list is such that you merely indicate the class
to be utilized as an event handler so there's no way to actually add an
event handler (at least that I can see) for working object.
Second, handler's would need to be dynamically created and destroyed as
itemrenderers are created and destroyed - but if I can't access the working
objects as they're being created.
I mean, I guess I can listen for the creation of the ir object from the
list, and then add an event handler - but still, even if I do that, it
seems I can only add the handler to the list class - but it's the list
class. Do I need to extend it? No - I guess I can reference it, add a
handler, then point the handler to the view? If so, that's still doing the
same thing I was doing before. I'm calling a function of a parent class
from within a child.
This is starting to sound much more complicated than I'd imagine it should
be.
Is there an easy way round these issues? Am I missing the point? I found a
few "suggestions" on stackoverflow - but they're just as hacky as anything
I've tried or thought of.
On Thu, Oct 10, 2013 at 10:19 AM, Thomas Wright <twri...@yesco.com> wrote:
Ok, thanks.
I can't remember why I even started doing this in the first place -
honestly.
I do remember having problems with dispatching an event in one particular
circumstance, so I did this and didn't look back.
Bad habits die hard I guess.
Thanks for the response :)
On Thu, Oct 10, 2013 at 9:24 AM, Jeffry Houser <jef...@dot-com-it.com>wrote:
On 10/10/2013 11:14 AM, Thomas Wright wrote:
Second - is there a better way to handle this, or is this legit?
From an encapsulation perspective, the renderer shouldn't know its
parents.
I always recommend dispatching an event, that bubbles from the renderer
and then handling it in the component that contains the list.
In terms of memory management; I'm not sure though. With your approach
you are creating a dependency on the list itemRenderer to its parent two
levels up.
By using events that bubble, you are not creating that dependency.
--
Jeffry Houser
Technical Entrepreneur
http://www.jeffryhouser.com
203-379-0773
--
*Thomas Wright*
Software Engineer
Extension: 1054
Office: [801] 464.4600
Corporate Division
twri...@yesco.com
--
Lee Burrows
ActionScripter