DIGG IT!
Published
Thursday, October 09, 2003
at
8:37 AM
.
I am working on my presentation for max and found something interesting. In V2 component, each component gets an queue for the various events supported. These queues are created when addEventListener is called.
Basically __q_click is the queue for the 'click' event. The naming convention goes as follows:
"__q_" +Event.type >> See mx.core.events.EventDispatcher & UIEventDispatcher
Although what is strange is that __q_click is a function!!! Yes, instead of putting listeners in an array, MM hid then inside a function and __q_click is also protected with ASSetPropFlags so you will not find it looping accross a component.
Here is a sample:
1. ADD a FUI v2 "Button to the stage
2. Name the instance "myComponent" >>> Case Sensitive now!!!
3. Add this code to the main timeline
//create a simple function
myClick = function(){trace('myClick')}
dog = {click:function(){trace('dog.click')}}
//add the function directly as a listeners
myComponent.addEventListener('click', myClick)
myComponent.addEventListener('click', dog)
//trace the queue
trace(myComponent.__q_click)
//loop through the queue and trace the listeners
for (var x in myComponent.__q_click){
trace(x +':'+myComponent.__q_click[x])
}
//execute the listener directly
myComponent.__q_click[0]()
What is weird to notice is that execution order is the reverse of the order the items were added. Basically this is symbolic of using a for loop in an object/function. When you use a for loop, you are looping through the order items are stored in raw memory and thus items added later go first.
This also presents a fairly simple hack to clear all listeners of a certain type:
myComponent.__q_click = function(){}
Although this would be better implemented in as a prototype method. Bad Ted, Bad!
See you at MAX in Novmeber.
ted ;)
0 Responses to “__q_click >> Click Event Queue in FUI V2 Components”
Post a Comment