I think bubbling the event is the easiest way to do it. This way you can
catch the event where it makes the most sense to handle it. For example,
you can add the event handler to the List (or DataGrid or whatever) which
is up the display-list chain from the itemRenderer and have the function
be owned by the class which is displaying the list.

Or, you can go up further and have it handled at the Application level -
if that makes sense for your app.

The neat part about bubbling the event is that you can have the event
handled in several places as appropriate and stop its propagation along
the way. For instance, you might have a last-chance event handler at the
Application level. Then in some other class, listen for the event on the
List. This lower-level event handler might look at the event, decide it
doesn't need to handle it and just let it go on up to the Application. Or,
if the event should be handled, stop its propagation.

There are lots of possibilities.

Peter Ent
Flex SDK Team
Adobe Systems

On 10/11/13 12:00 PM, "Thomas Wright" <twri...@yesco.com> wrote:

>ok ok, I get what you guys are saying.
>Gotcha, thanks :)
>
>
>On Fri, Oct 11, 2013 at 9:45 AM, Lee Burrows
><subscripti...@leeburrows.com>wrote:
>
>> 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
>>
>>
>
>
>-- 
>*Thomas Wright*
>Software Engineer
>Extension: 1054
>Office: [801] 464.4600
>
>Corporate Division
>twri...@yesco.com

Reply via email to