The way I do this is to add the custom parameters to the object that
is sending the event. Something like...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical" 
        creationComplete="onCreationComplete(event)">
        <mx:Script>
                <![CDATA[
                        import mx.controls.Button;
                        import mx.events.FlexEvent;
                        import mx.controls.Alert;
                        
                        private var myButton:Button = new Button();
                        private var myParameters:Object = new Object();
                        
                        private function 
onCreationComplete(event:FlexEvent):void
                        {
                                myButton.label = "Test Button";
                                myButton.addEventListener(MouseEvent.CLICK, 
myButtonWasClicked);
                                myParameters.foo = "Foo";
                                myParameters.bar = "Bar";
                                myButton.data = myParameters;
                                this.addChild(myButton);
                        }
                        
                        private function 
myButtonWasClicked(event:MouseEvent):void
                        {
                                Alert.show(event.currentTarget.data.foo + " = " 
+
event.currentTarget.data.bar);
                                myParameters.foo = "SNAFU";
                                myParameters.bar = "This";
                        }
                ]]>
        </mx:Script>
</mx:Application>


--- In [email protected], "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?
>


Reply via email to