This content has been marked as final. Show 5 replies
It's giving an example of something that you could do to dispatch the
event. It assumes that you've already put an event listener that calls
onButtonClick() on a subcomponent of your component.
This specifies to Flex that your event myEvent should be treated as an event.
2. create action script:
This shows how the Button click results in a standard Flex event being dispatched (MouseEvent.CLICK), and that within the handler of that event you manually dispatch an instance of your custom event.
3. This should how you register an event listener for your custom event for some component.
4. This shows what should happen when the listener for the custom event event is called.
So in essence, you declare that you will use a custom event, you dispatch the custom event in the listener of a Flex event, and some listener added to a component gets called.
FB3 help sys on custom events will help further understand the flow.
My question is that, to users, they see no difference to a click event. Then what is the benefit of doing this? What is so special of doing this?
My guessing is that main component can be triggered and call the myCustomEvent and run some actions. In the other hand, if using the built-in click event, I can only call some function inside the custom component? Is that the benefit of using custom event?
"cpthk" <email@example.com> wrote in message
> My question is that, to users, they see no difference to a click event.
> what is the benefit of doing this? What is so special of doing this?
> My guessing is that main component can be triggered and call the
> and run some actions. In the other hand, if using the built-in click
> event, I
> can only call some function inside the custom component? Is that the
> benefit of
> using custom event?
The parent component can listen for a click event on a child of your custom
component, sort of. It can listen for a click event on your custom
component and then check if the target is of the class that it wants, and
then if it is the correct one. But if that component has children itself,
that can get to be a problem (such as a button...if you click on its label,
when you test to see if the target is a button, it isn't).
So this makes everyone's life a lot easier by giving specific information
about what happened in your component.
The point here is that the parent of the component can listen for the custom event and do something specific. If you have five buttons in the custom component, the parent of the component can do five different thiings depending on what custom event it gets.
If you just use the click event, the parent of the component has to figure out what the label of the event currentTarget is, and perhaps also check the parent of the Button, because the parent of the component dispatching the event may have several custom components in it.