[flexcoders] Re: passing parameters to eventlistener functions

2008-04-24 Thread Amy
--- In flexcoders@yahoogroups.com, "netdeep" <[EMAIL PROTECTED]> wrote:
>
> Thanks for the reply Todd.  What about processing the event 
though?  For example if I 
> have:
> 
> foo.addEventListener(MouseEvent.MOUSE_DOWN, processResult);
> 
> But I want to define processResult so that I can pass it a number 
or an object, how do I 
> use Custom events?  The even I'm want to listen for is the moue 
down event.  When I 
> define this listener, I know the value I want to associate with 
that event.  Later on, I won't 
> know it so that when processResult gets called, it needs that extra 
parameter to work.  I'm 
> a bit confused about how to use the custom event there, since I 
won't be the one 
> dispatching it.

OK, say that whatever the mouse is down on is a child of an 
itemRenderer that is representing an XML data source, and you want to 
get the node index of the XML node that is being represented.

private function myMouseDownListener(e:event):void{
   //assume for simplicity we know what was clicked
   //is always going to be a direct child of the renderer
   var parent:* = e.target.parent;
   var d:XML = parent.data;
   var nodeNum:int = d.childIndex();
}

Depending on what you are trying to do, you can usually extrapolate 
from the target of the event to what you need to know using the 
parent or the owner chain.

However, if you really feel the need to go with custom events, this 
is a good article I have found helpful:

http://www.adobe.com/devnet/flex/articles/graduating_pt2.html

HTH;

Amy



[flexcoders] Re: passing parameters to eventlistener functions

2008-04-24 Thread valdhor
The way I do this is to add the custom parameters to the object that
is sending the event. Something like...


http://www.adobe.com/2006/mxml";
layout="vertical" 
creationComplete="onCreationComplete(event)">






--- In flexcoders@yahoogroups.com, "netdeep" <[EMAIL PROTECTED]> wrote:
>
> 
> I need to pass a parameter to a function using actionscript. 
However by default, all you can 
> pass are events to the function called by an eventlistener.  I know
this is easy to do in MXML, 
> but can it be done in actionscript?  The documentation has this to
say about it:
> 
> "Because the second parameter of addEventListener() is a function,
you cannot specify 
> parameters of that function in the addEventListener() call. So, to
pass additional parameters 
> to the listener function, you must define them in the listener
function and then call the final 
> method with those parameters."
> 
> But what does it mean to "call the final method with those
parameters".  No examples are 
> given.  Could someone give me a quick example of how this is done?
>




[flexcoders] Re: passing parameters to eventlistener functions

2008-04-24 Thread netdeep
Thanks for the reply Todd.  What about processing the event though?  For 
example if I 
have:

foo.addEventListener(MouseEvent.MOUSE_DOWN, processResult);

But I want to define processResult so that I can pass it a number or an object, 
how do I 
use Custom events?  The even I'm want to listen for is the moue down event.  
When I 
define this listener, I know the value I want to associate with that event.  
Later on, I won't 
know it so that when processResult gets called, it needs that extra parameter 
to work.  I'm 
a bit confused about how to use the custom event there, since I won't be the 
one 
dispatching it.



--- In flexcoders@yahoogroups.com, "twcrone70" <[EMAIL PROTECTED]> wrote:
>
> Create a custom event that has a field or fields that hold your
> parameter(s).  When you create the event for dispatching you can then
> add the parameter(s) and since that event is passed in to the handler
> method, you will have the parameter(s) in the event instance.
> 
> >>>
> package mypkg
> {
>import flash.events.Event;
> 
>/**
> * Custom event that holds extra data.  Insipred by Cliff Hall's
> PureMVC framework
> * and usage of Notifications.
> *  
> * @author Todd Crone
> */
>public class CustomEvent extends Event
>{
>   /**
>* The data associated with the event. 
>*/
>   public var body:Object;
>   
>   /**
>* Constructor.
>*  
>* @param type
>*The event type.
>* @param body
>*The body for this custom event.
>* @param bubbles
>*Whether or not this event bubbles up the component
> hierarchy or not.
>* @param cancelable
>*Is this event cancelable by a listener.
>*/
>   public function CustomEvent( type:String, 
>body:Object, 
>bubbles:Boolean = false, 
>cancelable:Boolean = false )
>   {
>  super( type, bubbles, cancelable );
>  
>  this.body = body;
>   }
>   
>}
> }
> 
> <<<
> 
> Hope this helps!
> 
> - Todd
> 
> 
> --- In flexcoders@yahoogroups.com, "netdeep"  wrote:
> >
> > 
> > I need to pass a parameter to a function using actionscript. 
> However by default, all you can 
> > pass are events to the function called by an eventlistener.  I know
> this is easy to do in MXML, 
> > but can it be done in actionscript?  The documentation has this to
> say about it:
> > 
> > "Because the second parameter of addEventListener() is a function,
> you cannot specify 
> > parameters of that function in the addEventListener() call. So, to
> pass additional parameters 
> > to the listener function, you must define them in the listener
> function and then call the final 
> > method with those parameters."
> > 
> > But what does it mean to "call the final method with those
> parameters".  No examples are 
> > given.  Could someone give me a quick example of how this is done?
> >
>





[flexcoders] Re: passing parameters to eventlistener functions

2008-04-24 Thread twcrone70
Create a custom event that has a field or fields that hold your
parameter(s).  When you create the event for dispatching you can then
add the parameter(s) and since that event is passed in to the handler
method, you will have the parameter(s) in the event instance.

>>>
package mypkg
{
   import flash.events.Event;

   /**
* Custom event that holds extra data.  Insipred by Cliff Hall's
PureMVC framework
* and usage of Notifications.
*  
* @author Todd Crone
*/
   public class CustomEvent extends Event
   {
  /**
   * The data associated with the event. 
   */
  public var body:Object;
  
  /**
   * Constructor.
   *  
   * @param type
   *The event type.
   * @param body
   *The body for this custom event.
   * @param bubbles
   *Whether or not this event bubbles up the component
hierarchy or not.
   * @param cancelable
   *Is this event cancelable by a listener.
   */
  public function CustomEvent( type:String, 
   body:Object, 
   bubbles:Boolean = false, 
   cancelable:Boolean = false )
  {
 super( type, bubbles, cancelable );
 
 this.body = body;
  }
  
   }
}

<<<

Hope this helps!

- Todd


--- In flexcoders@yahoogroups.com, "netdeep" <[EMAIL PROTECTED]> wrote:
>
> 
> I need to pass a parameter to a function using actionscript. 
However by default, all you can 
> pass are events to the function called by an eventlistener.  I know
this is easy to do in MXML, 
> but can it be done in actionscript?  The documentation has this to
say about it:
> 
> "Because the second parameter of addEventListener() is a function,
you cannot specify 
> parameters of that function in the addEventListener() call. So, to
pass additional parameters 
> to the listener function, you must define them in the listener
function and then call the final 
> method with those parameters."
> 
> But what does it mean to "call the final method with those
parameters".  No examples are 
> given.  Could someone give me a quick example of how this is done?
>