Flex Certification » Flex Certification, Flex Questions » Flex Events
Flex Events
Event handlers are the functions or methods that
you write to respond to specific events. They are also sometimes referred to as event listeners.
Does Events occur only through User Interection?
Events can also occur without any direct user
interaction, such as when data finishes loading from a server or when an attached camera becomes active. You can
“handle” these events in your code by adding an event handler.
Which event model is Flex event model based on?
The Flex event model is based on the Document Object Model (DOM) Level 3 events model. Although Flex does
not adhere specifically to the DOM standard, the implementations are very similar.
What is a the Target Node?
The target node is the node in the display
list where the event occurred.
All visual objects, including Flex controls and containers, are subclasses of ?
DisplayObject class.
What are the phases of event flow?
1.The capturing phase
2. The targeting phase.
3. The bubbling
phase
What is the Capturing Phase?
The first part of the event flow is called the capturing phase. This phase comprises all of the nodes from the root
node to the parent of the target node. During this phase, Flash Player examines each node, starting with the root,
to see if it has a listener registered to handle the event, sets values of the Event object, and calls the listener
What is the targeting phase?
The second part of the event flow, the targeting phase, consists solely of the target node.Flash Player sets the appropriate
values on the Event object, checks the target node for registered event listeners, and then calls those
listeners
What is the bubbling phase?
The third part of the event flow, the bubbling phase, comprises all of the nodes from the target node’s parent to the
root node. Starting with the target node’s parent, Flash Player sets the appropriate values on the Event object and
then calls event listeners on each of these nodes. Flash Player stops after calling any listeners on the root node.
Do we have to create the Event Object in a Flex application?
An Event object is an implicitly created object, similar to the request and response objects in a
JavaServer Page (JSP) that are implicitly created by the application server.
Does flex create multiple event objects while bubbling and capturing phases?
NO, Flex
changes the values on the Event object as it moves up or down the display list, rather than creating a new Event
object for each node.
What are the main subclasses of flash.events.Event class?
•mx.events.*
•flash.events.*
mx.messaging.events.ChannelEvent
mx.logging.LogEvent.
What classes are there in mx.events package?
The mx.events package defines event classes that are specific to Flex controls, including the DataGridEvent,
DragEvent, and ColorPickerEvent.
What classes are there in flash.events package?
The flash.events package describes events that are not unique to Flex but are
instead defined by Flash Player. These event classes include MouseEvent, DataEvent, and TextEvent. All of these
events are commonly used in Flex applications.
What do you know about EventDispatcher class?
Every object in the display list can trace its class inheritance back to the DisplayObject class. The DisplayObject
class, in turn, inherits from the EventDispatcher class. The EventDispatcher class is a base class that provides important event model functionality for every object on the display list.
The EventDispatcher class implements the IEventDispatcher interface. This allows developers who create custom
classes that cannot inherit from EventDispatcher or one of its subclasses to implement the IEventDispatcher
interface to gain access to its methods.
The addEventListener() method is the most commonly used method of this class. You use it to register your
event listeners.
How can we manually dispatch an event?
Using dispatchEvent()
var result:Boolean = b1.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true,
false));
}
<mx:Button id=”b1″
label=”Click Me”
mouseOver=”b1.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));”
/>
How can we know if an there is an event listener for that specific event type
on a particular display list object.
Using hasEventListener()
Why is it better to use addEventListener() rather then doing it inline using MXML?
This method gives you greater control over the event by letting you
configure the priority and capturing settings, and use event constants. In addition, if you use
addEventListener() to add an event handler, you can use removeEventListener() to remove the handler
when you no longer need it.
Can you call removeEventListener(). If you add an event handler inline?
NO.
How do you access the target properties from event object
TextInput(e.currentTarget).setSelection(0,3);
What are the different stratergies for registering the event handlers with your Flex Controls?
1.Define an event handler inline. <mx:Button id=”b1″ label=”Click Me” click=”myEventHandler(event)”/>
2Use the addEventListener() method
<mx:Script><![CDATA[
import mx.controls.Alert;
private function createListener():void {
b1.addEventListener(MouseEvent.CLICK, myClickHandler, false, 0);
}
private function myClickHandler(e:MouseEvent):void {
Alert.show("The button was clicked.");
}
]]></mx:Script>
<mx:Button id=’b1′
label=”Click Me”
initialize=’b1.addEventListener(MouseEvent.CLICK, myClickHandler, false, 1);’
/>
3Create an event handler class and register components to use the class for event handling.
AddEventListener Method Signature
The addEventListener() method has the following signature:
componentInstance.addEventListener(
event_type:String,
event_listener:Function,
use_capture:Boolean,
priority:int,
weakRef:Boolean
)
Explain use_capture parameter of the addEventListener() method?
The use_capture parameter of the addEventListener() method lets you control the phase in the event flow in
which your listener will be active. It sets the value of the useCapture property of the Event object. If useCapture
is set to true, your listener is active during the capturing phase of the event flow. If useCapture is set to false,
your listener is active during the targeting and bubbling phases of the event flow, but not during the capturing
phase. The default value is determined by the type of event, but is false in most cases.
How can we listen for an event during all phases of the event flow?
To listen for an event during all phases of the event flow, you must call addEventListener() twice, once with the
useCapture parameter set to true, and again with use_capture set to false.
Explain priority parameter of the addEventListener() method?
The priority parameter sets the priority for that event listener. The higher the number, the sooner that event
handler executes relative to other event listeners for the same event. Event listeners with the same priority are
executed in the order that they were added.
Explain weakRef parameter of the addEventListener() method?
The weakRef parameter provides you with some control over memory resources for listeners. A strong reference
(when weakRef is false) prevents the listener from being garbage collected. A weak reference (when weakRef is
true) does not. The default value is false.
Using nested inner functions as event listeners (Closure).
private function initApp():void {
b1.addEventListener(“click”,
function(e:Event):void {
Alert.show(“The button was clicked.”);
}
);
Important thing to remember if you have to remove event listener?
You can remove only event listeners that you added with the addEventListener() method in an ActionScript
block. You cannot remove an event listener that was defined in the MXML tag, even if it was registered using a
call to the addEventListener() method that was made inside a tag attribute.
How can you define multiple listeners for a single event?
<mx:Button id=”b1″
label=”Do Both Actions”
click=’submitForm(event); debugMessage(event);’
OR
public function createHandlers(e:Event):void {
b1.addEventListener(MouseEvent.CLICK, submitForm);
b1.addEventListener(MouseEvent.CLICK, debugMessage);
}
Can you set the priority for a listener function if you added the event listener
using MXML inline.
NO, You cannot set a priority for a listener function if you added the event listener
using MXML inline.
Can Validator have capuring & bubbling Phase?
No, Only DisplayObject objects (visual objects such as containers and controls) can have a capturing phase and a
bubbling phase in addition to the targeting phase.
Any event can be captured, but no DisplayObject
objects listen during the capturing phase unless you explicitly instruct them to do so. In other words, capturing is
disabled by default.
What are target and currentTagret Properties?
Every Event object has a target and a currentTarget property that help you to keep track of where it is in the
process of propagation. The target property refers to the dispatcher of the event. The currentTarget property
refers to the current node that is being examined for event listeners.
You should use the
event.currentTarget property rather than the event.target property
<mx:Button label=”OK” click=”trace(event.currentTarget.label)”/>
In this case, in the Button event’s click event listener, the event.currentTarget property always refers to the
Button, while event.target might be either the Button or its UITextField, depending on where on the Button
control the user clicked
By default, no container listens during the capturing phase.
If you add an event listener inline with MXML, Flex sets this argument to false. How can you override this value?
You cannot.
What methods are called to prevent an Event object from continuing on it’s way through the event flow?
•stopPropagation()
•stopImmediatePropagation()
What is the different between •stopPropagation()
•stopImmediatePropagation()?
stopPropagation() method prevents the Event object from moving on to the next node, but only after any other
event listeners on the current node are allowed to execute.
The stopImmediatePropagation() method also prevents the Event objects from moving on to the next node,
but it does not allow any other event listeners on the current node to execute.
Filed under: Flex Certification, Flex Questions · Tags: Flex Certification, Flex Questions









This one’s great!
Thanks