Friday, April 2, 2010

How to catch event?

Hi,

I usually use event connected with visual control, but now I would like to manually dispatch event, when I succesfully receive data from my mySQL database, and change a couple of visual controls in a few custom components. Do you know any example in the net, or could give me some tips?

Best regards.

How to catch event?

Read the Flex 3 docs about Dispatching Custom events.

How to catch event?

To dispatch an event you want a component that implements IEventDispatcher or extends EventDispatcher.

To dispatch an event from such a component:

dispatchEvent( new Event( ''eventName'' ) );

To add a listener for the event:

dispatcher.addEventListener( ''eventName'', eventHandlerFunction );

Let me know if that helps...


Ben Edwards

My english isn't so good, so please correct me if I'm wrong:

Currently, I have application in which I have 2 components, let's name it Comp1 and Comp2 (containing several standard controls like text input, label, combobox etc.)?and 1 module loaded (let's name it Mod1) dynamically into one of that component (Comp2). In this module I have another component -%26gt; Comp3, with combobox. When I change the value of this combobox, I connect to mySQL database, get the data and ... I would like to change a several controls in Comp1.

So...

First of all, I should create a components Comp1, Comp2 and Comp3 which implements IEventDispatcher.

In Comp3 I have the data from my database, and there I should dispatch event and place my data in event object.

In Comp1 I should add listener for this event using addEventListener()

Am I right?

Mariusz

Yes, it sounds like you are on the right track.?Mod1/Comp3 will dispatch events and Comp1/Comp2 will listen for them with addEventListener().

Good work.

Ben Edwards

No comments:

Post a Comment