Hello Marco,
BroadcastEvent() exists mainly for compatibility purpose with older versions. It has a disadvantage of notifying only views which are part of the view tree. Today I would recommend to use the System Event and System Event Handler as infrastructure to propagate notifications. Unlike BroadcastEvent() this technique is also able to notify objects which are not part of view tree. Although the mentioned documentation addresses the usage of System Event to handle event generated by the device, this approach can also be used to handle events generated locally in the UI. See also Trigger System Events locally from Chora code.
If you nevertheless want to use the BroadcastEvent() approach, following are the necessary steps:
Step 1: Implement your own Event class. This class has to descend from Core::Event. Inside your class you can add data members, e.g. variables, etc., where information associated with the event can be stored.
Step 2: To broadcast the event, create an instance of your class (step 1), initialize its variables with data you want to send with the event and pass the instance to BroadcastEvent() method. For example:
var Application::Event event = new Application::Event;
event.Data = "Some text to provide with the event.";
rootthis.BroadcastEvent( event, Core::ViewState[]);
Step 3: To react to the event, in the affected component override the method HandleEvent() and implement it as shown below:
// Invoke the inherited version of the method 'HandleEvent'.
// Remove the line if the inherited code should not be executed.
var object result = super( aEvent );
// Try to cast the event object to your event class.
var Application::Event event = (Application::Event)aEvent;
// If the received event object is of your event class, handle the event.
if ( event )
{
trace event.Data;
}
// Return the result of the operation.
return result;
I hope it helps you further.
Best regards
Paul Banach