[flexcoders] Re: Inline EventListener in MXML tags - confusing description in Developers guid

2008-07-21 Thread florian.salihovic
Instead of waiting for an answer i just ran a lil' test:
?xml version=1.0 encoding=utf-8?
mx:Application creationComplete=eventListener(event)
xmlns:mx=http://www.adobe.com/2006/mxml;
  mx:Script
![CDATA[
  import flash.utils.getQualifiedClassName;
  import mx.events.FlexEvent;

  private function eventListener(event:Event):void {
trace(getQualifiedClassName(event)+#+event.type);
switch(event.type) {
  case FlexEvent.APPLICATION_COMPLETE:
this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
this.removeEventListener(FlexEvent.CREATION_COMPLETE,
eventListener, false);
this.removeEventListener(FlexEvent.APPLICATION_COMPLETE,
eventListener, false);
this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
break;
  case FlexEvent.CREATION_COMPLETE:
this.removeEventListener(FlexEvent.CREATION_COMPLETE,
eventListener, false);
this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
this.addEventListener(FlexEvent.APPLICATION_COMPLETE, eventListener,
false, 0, true);
this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
break;
}
  }
  private function registeredEventListenerTrace(type:String):void {
trace(\t + type +  is registered:  +
this.hasEventListener(type));
  }
]]
  /mx:Script
/mx:Application

I was surprised that the FlexEvent.CREATION_COMPLETE can't be removed. This is 
quite 
shocking...

Best regards.

--- In flexcoders@yahoogroups.com, florian.salihovic [EMAIL PROTECTED] 
wrote:

 Quoted from Adobe Flex Developers Guide, page 78
 
 However, it is best practice to use the addEventListener() method.
 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. If you add an event handler inline, you cannot call removeEventListener()
 on that handler.
 
  - End of Quote -
 
 What i think is a little bit confusing is, that it's said that inline 
 EventListener can't be 
 removed? Or is it just a little bit unluckily expressed? Why can't i just 
 call 
 removeEventListener in ActionScript on the type of event declared in MXML?
 
 Best regards from Germany




Re: [flexcoders] Re: Inline EventListener in MXML tags - confusing description in Developers guid

2008-07-21 Thread Johannes Nel
you could compile with the -keep option to see what is output underneath the
covers.
and then what i think might be the case
pure speculation follows
consider that the mxml gets converted to as. now in mxml you could have
something event={a=1}
or
something event=function(event,'sdfdsf')
or...
now if i was to write a converter for something like this i would wrap the
function which invokes whatever the user specified (i am not certain if this
is the case) in order to make my approach as flexible as possible

jpn

On Mon, Jul 21, 2008 at 12:18 PM, florian.salihovic 
[EMAIL PROTECTED] wrote:

   Instead of waiting for an answer i just ran a lil' test:
 ?xml version=1.0 encoding=utf-8?
 mx:Application creationComplete=eventListener(event)
 xmlns:mx=http://www.adobe.com/2006/mxml;
 mx:Script
 ![CDATA[
 import flash.utils.getQualifiedClassName;
 import mx.events.FlexEvent;

 private function eventListener(event:Event):void {
 trace(getQualifiedClassName(event)+#+event.type);
 switch(event.type) {
 case FlexEvent.APPLICATION_COMPLETE:
 this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
 this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
 this.removeEventListener(FlexEvent.CREATION_COMPLETE,
 eventListener, false);
 this.removeEventListener(FlexEvent.APPLICATION_COMPLETE,
 eventListener, false);
 this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
 this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
 break;
 case FlexEvent.CREATION_COMPLETE:
 this.removeEventListener(FlexEvent.CREATION_COMPLETE,
 eventListener, false);
 this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
 this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
 this.addEventListener(FlexEvent.APPLICATION_COMPLETE, eventListener,
 false, 0, true);
 this.registeredEventListenerTrace(FlexEvent.CREATION_COMPLETE);
 this.registeredEventListenerTrace(FlexEvent.APPLICATION_COMPLETE);
 break;
 }
 }
 private function registeredEventListenerTrace(type:String):void {
 trace(\t + type +  is registered:  +
 this.hasEventListener(type));
 }
 ]]
 /mx:Script
 /mx:Application

 I was surprised that the FlexEvent.CREATION_COMPLETE can't be removed. This
 is quite
 shocking...

 Best regards.

 --- In flexcoders@yahoogroups.com flexcoders%40yahoogroups.com,
 florian.salihovic [EMAIL PROTECTED] wrote:
 
  Quoted from Adobe Flex Developers Guide, page 78
 
  However, it is best practice to use the addEventListener() method.
  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. If you add an event handler inline, you cannot call
 removeEventListener()
  on that handler.
 
  - End of Quote -
 
  What i think is a little bit confusing is, that it's said that inline
 EventListener can't be
  removed? Or is it just a little bit unluckily expressed? Why can't i just
 call
  removeEventListener in ActionScript on the type of event declared in
 MXML?
 
  Best regards from Germany
 

  




-- 
j:pn
\\no comment


[flexcoders] Re: Inline EventListener in MXML tags - confusing description in Developers guid

2008-07-21 Thread Amy
--- In flexcoders@yahoogroups.com, Johannes Nel [EMAIL PROTECTED] 
wrote:

 you could compile with the -keep option to see what is output 
underneath the
 covers.
 and then what i think might be the case
 pure speculation follows
 consider that the mxml gets converted to as. now in mxml you could 
have
 something event={a=1}
 or
 something event=function(event,'sdfdsf')
 or...
 now if i was to write a converter for something like this i would 
wrap the
 function which invokes whatever the user specified (i am not 
certain if this
 is the case) in order to make my approach as flexible as possible
 

One difference between adding a listener inline and adding a listener 
in AS3 is that inline you have a choice of arguments...you can have 
no argument, an arbitrary argument, or send the event.  In AS3, the 
event is always passed.   If your function doesn't expect to get the 
event as its one and only argument, you will get a runtime error.

This does imply that whatever goes on in addEventListener, it is way 
stricter than what happens when you add the listener inline.  It 
would be nice if the finer points were documented.

HTH;

Amy