Can I pass a second var to the listener function.

new to actionscript and it can not find on google... I don't know it exists, but I have worked around him twice and really want to do it now and do not know how.

When you add an event listener

mybutton.addEventListener(MouseEvent.Mouse_UP, myListener);

the above passes 1 variable of type event.

I catch it as follows:

private function myListener(eventVar:Event):void { //code }

all is good.

I would like to pass more variables to this event listener though.

e.g.
myButton.addEventListener(MouseEvent.Mouse_UP, myListener(what_goes_here, myVariable1:String, myEtc:int));

private function myListener(e:Event, myVar:String, myEtc:int) { }

don't know what is supposed to go in the 'what_goes_here' part of the code above so that it works.

Any help much appreciated.

TongueDar wrote:

I don't know if it will help - and I probably do all wrong, but if you build the button in its own function, you can pass in local variables.

So, something like this;

function newButton(tBtn:Sprite, varA:String, varB:int):void
{
    tBtn.addEventListener(MouseEvent.MOUSE_UP, btnUp);
    function btnUp(event:MouseEvent):void {
        // do something with the passed in variables.
    }
}

newButton(TargetSprite, "string", 0);

It is more common to assign a variable typed using a function returned the same type:

for example:

private var firstButton:Button;
private var secondButton:Button; 

firstButton = createButton("First Button", 50, 25);
secondButton = createButton("Second Button", 80, 40);

private function createButton(label:String, width:int, height:int):Button
     {
     var result:Button = new Button();
     result.label = label;
     result.width = width;
     result.height = height;
     result.addEventListener(MouseEvent.CLICK, mouseEventClickHandler);

     return result;
     }

private function mouseEventClickHandler(evt:MouseEvent):void
     {
     switch (evt.currentTarget)
            {
            case firstButton:    trace("first button was clicked");
                                 break;

            case secondtButton:  trace("second button was clicked");
            }
     }

in the example above, you can simply use evt.currentTarget.label + 'has been clicked' instead, but it was written just to show how to handle multiple calls with the same function event.

Tags: BlackBerry Developers

Similar Questions

  • in hotmail, I can't pass on all messages that the coordinates and the message is not transferred to the new email.

    In hotmail, I can't pass on all messages that the coordinates and the message is not transferred to the new email. However, this works in Windows Live Mail. I use Windows 7 64-bit and 64-bit internet.

    Hello Brian,.

    There is a forum located there that is specifically for Windows Live Hotmail problems. Here is the link:
  • How can I display an error message on the listening port close popup without closing the popup.

    Hi Experts,

    JDeveloper 12.1.3.0.0

    How can I display an error message on the listening port close popup without closing the popup.

    Thank you

    Roy

    As its name suggests, close listener of popup is called when popup is closed so you can not do this.

    If you want to display the popup message, use your own buttons instead of the ok/cancel default buttons and close the popup programmatically.

    Dario

  • Can I have a second service on the same vswitch console?

    I currently have a client with the shortage of nic. I want VLAN its iSCSI traffic but so the Service Console would be unable to talk to the table. Can I add a second service console to the same vswitch as the existing SC and tag its traffic?

    Thank you

    Yes you can just add a second portgroup to SC for the same vSwitch and give it the appropriate tag of VLAN

    Alex

    www.phdvirtual.com

  • How can I pass/add these results in the column of the motion of my hand

    Hello Experts

    I'm working on a subquery. My subquery works very well and gives the results I need. But how do I pass/add these results in the column of the motion of my hand "MGRNAME". Here's my query

    Select pc.c_id 'Project ID',
    CN. C_ID 'Customer ID', cn.c_last "Last Name", "First Name", cn.c_first
    PJ.mgr_id 'ID Manager', 'Project', MGRNAME pj.project_name
    project_consultant PC
    Join them consultant cn
    on (pc.c_id = cn.c_id)
    Join the pj project
    on (pc.p_id = pj.p_id)
    where lower (cn.c_last) = "myers.

    and MGRNAME in
    (select concat (substr (c_last, 1, 20),
    substr (c_first, 1, 20))
    as consultant MGRNAME
    where c_id in (102, 103)
    )

    When I run the above query, I got error.

    Many thanks in advance
    SELECT pj.p_id         "Project ID",
           cn.c_id         "Client ID",
           cn.c_last       "Last Name",
           cn.c_first      "First Name",
           pj.mgr_id       "Manager ID",
           pj.project_name "Project",
           SUBSTR (mgr.c_last, 1, 20) || ' ' || SUBSTR (mgr.c_first, 1, 20) AS mgrname
      FROM project_consultant pc,
           consultant cn,
           project pj,
           consultant mgr
     WHERE pc.c_id = cn.c_id
       AND pc.p_id = pj.p_id
       AND pj.mgr_id = mgr.c_id
       AND mgr.c_id IN (102, 103)
       AND LOWER (cn.c_last) = 'myers';
    

    isotope

  • Possible to access the listener function in another class?

    I want a listener on a tween on the document class when it is finished, it goes to the listener of its child function, but I don't know how.  I thought it would be just a case of document.functionName, but it is throwing an error.

    I've got:

    treeWidth_tw.addEventListener (TweenEvent.MOTION_FINISH, Bauble.startFade) in the parent document

    and in the mc of the child:

    public void startFade(evnt:TweenEvent) {}

    fadeTween = new Tween(this,"alpha",Regular.easeIn,0,1,3,true)

    }



    I get the error message:

    1061: call to a startFade method maybe not defined through a reference with static type class.

    Is the class trinket or is it and the instance name?

    Generally, class names begin with a capital letter and instance names are tiny. So I guess that bauble is the name of the class.

    In this case Flash expects a static class called startFade method. So to you class file you defined:

    public static void fadeStep()

    or is it defined as an instance method?

  • How the parameter values can be passed to OBIEE reports of the user interface

    Hello

    Does anyone have an idea on how to pass parameters to the UI (user interface of a java application) to
    OBIEE report page. Based on the value of the parameter passed, the report page should be displayed for ex: the product
    name must be selected in the user interface, then the page of the report must show sales for this product
    Alone.can u please let me know how this can be achieved. Any help would be appreciated.

    Thank you
    Leela

    Hi Leela,
    What you're looking for can be accomplished with GO URL, see here:
    http://download.Oracle.com/docs/CD/E12096_01/books/AnyWebAdm/AnyWebAdm_APIWebIntegrate6.html#wp1005251

    Kind regards
    Alastair

    Published by: AlastairB_UK on October 26, 2009 15:27

  • CAN I KEEP A SECOND COPY OF THE FILE ON THE CLOUD

    I tried to save a backup, second copy of a file on the CLOUD. But it seems that then the file on drive C: in the DOCUMENTS is missing. In other words, the file appears only in one place, but not the two places. OR, recorded in DOCUMENTS and then stored in the CLOUD, it removes the DOCUMENTS on the C drive.

    That is the way it should be, or is it a preference to allow these?

    "Drive C"?  It's a Windows term.  So I assume you mean primary storage to your Mac.

    Anyway, looks like you want only two copies of your document in the cloud.  Why not simply duplicate the original document?  You do not have to tell us what software you use to create this document, but Apple products like Pages and preview have a file > duplicate menu item.  They give the file duplicated a slightly different name from the original that is displayed when you perform the action in double.

  • Windows 7 Professional, can I pass its default language in the other, like German?

    Hey
    I have a question on my windows 7 professional language problem.
    When I bought the laptop the default language is English. But now I want for the shift in German? How to make possible?
    I knew the Ultimate version could change language 32 at will. What about that professional?
    Any suggestion...

    Hello

    You need Windows 7 Ultimate or enterprise, change language.

    "How can I get additional display languages?

    http://Windows.Microsoft.com/en-us/Windows7/how-do-I-get-additional-display-languages

    Note

    • Language packs are available in Windows 7 ultimate through Windows Update as optional updates. They are not installed automatically. If you are using Windows 7 Enterprise, contact your system administrator for more information about installing additional languages.

    See you soon.

  • My laptop is Vista 64 bit. Can I download my second copy of the creative cloud on that?

    My laptop is a Vista 64-bit os. Download PhotoShop, Illustrator and InDesign on this computer for my second computer? I have it on my desk and I have on my laptop too, but it has vista.

    Hello

    Please see the system requirements before you download: -.

    https://helpx.Adobe.com/creative-cloud/system-requirements.html

  • I can't add a second e-mail account. I get a message next to the 'User name' or password invalid password field. I can connect to the web gmail ok, imap is enabled.

    I setup a gmail account to and works very well. When I try to add another gmail account, I get an error 'User name' or invalid password. I can connect to this second gmail via the web to gmail account and the account active imap.

    PS - I use these accounts for the years through the web

    Thank you

    I also tried to delete completely the TB and reinstalled to try the problem gmail account and it still doesn't work.

    When checking on the 2-factor authentication, which I use, I noticed something. The work gmail account has allowed access to less secure applications"and my problem of account does not. I activated that and managed to add it to the TB. Everything works now!

    Not sure if less secure applications is a good thing, but its working.

    Thanks Christ1

  • A query can be passed to the user-defined function?

    Hello
    I created a function that takes one parameter and returns a value. Now tha value that is passed into the function comes also from a query, so can I pass that Charly directly in the parameter?
    I tried this but it is giving error: ORA-00936: lack of expression.
    select ID from table1
    where areaid=f_getAreaID(SELECT sec FROM table2 WHERE artid='3232') and 
    type='p002' 
    Above code is in error. How do I get my requirement?
    Note: Assume that query to the function will always return a value of skis.

    Published by: bootstrap on August 28, 2011 12:13

    Subquery must be enclosed in parentheses. Function parameters must be placed in brackets. Therefore, you should use

    select ID from table1
    where areaid=f_getAreaID((SELECT sec FROM table2 WHERE artid='3232')) and
    type='p002'
    

    Remember, it must be a scalar subquery (subquery returns one or no line).

    SY.

  • Pass variable from ColdFusion to the JavaScript window

    Hello world

    I have a java script window that will open when the user clicks on the link, my problem is that how can I pass a ColdFusion variable to the window. I use ColdFusion 7 so I can't use cfwindow.what should I put on the place * ? I tried to put EntityId in the location javascript:poponload (EntityId);   and function poponload (EntityId), not ' t not work then please let me know if you know how to do this.

    My code:

    < SCRIPT language = "javascript" >

    function poponload()

    {

    Window.Open (' test.cfm? test = '* , "mywindow", "menubar = 1, resizable = 1, width = 350, height = 250');

    }

    < /script >

    < body >

    < cfform >

    < cfset EntityId = '#form. EntityId #" > /i want to spend EntityId to the javascript window "

    < / cfif >

    < a href = "javascript:poponload();" "> find ID < /a >

    < / cfform >

    < / body >

    Thank you, Rob - appropriateness to the subject, not you (or someone) know what I'm doing wrong with the code below? (the message in the "alert" box is #x #, if the function is not picking up the Coldfusion variable, x). Thanks in advance!

  • SetCtrlVal used during the Thread function works causes memory leaks

    I am writing a program that works if... Or not work if... - see the next lines... :-)...

    The program includes a section, mostly GUI - and User Interaction.

    The other part is a DLL. In the DLL we readings on an external consultant controller RS232. Sometimes the controller card needs (called how much) time and this time must pass then the result can be read card controller... and so on...

    Blocking is not GUI-user-program for the expectation of the return value of the DLL functions (which need a few seconds to be finished) I start a thread in the DLL with

    CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE, THREAD_FunctionX, & tmpTFP, NULL);

    with "tmpTFP" as an instance of type "TYPE_THREAD_FUNCTION_PARAMETERS":

    typedef struct
    {
    //
    int IntVal1;                // 1. Integer-Wert
    int IntVal2;                // 2. Integer-Wert
    int IntVal3;                // 3. Integer-Wert
    int IntVal4;                // 4. Integer-Wert
    int IntVal5;                // 5. Integer-Wert
    //
    int IntBuffer1 [32];            // 1. Integer-buffer (aktuell genugt einer)
    //
    Double DblVal1;                // 1. Double-value
    Double DblVal2;                // 2. Double-value
    Double DblVal3;                // 3. Double-value
    Double DblVal4;                // 4. Double-value
    Double DblVal5;                // 5. Double-value
    //
    char CharVal1;                // 1. (Single)- Tank-Wert
    char CharVal2;                // 2. (Single)- Tank-Wert
    char CharVal3;                // 3. (Single)- Tank-Wert
    char CharVal4;                // 4. (Single)- Tank-Wert
    char CharVal5;                // 5. (Single)- Tank-Wert
    //
    char CharBuffer1 [1024];        // 1. Char buffer (akutell einer genugt)
    //
    } TYPE_THREAD_FUNCTION_PARAMETERS;

    In the GUI-user program - I get fast by default-return value of the thread start function.

    Then I asked the DLL (some global state variables are used for this) when it is finished.

    According to the map-controller (RS232) contacted the waiting time depends on the 'mood' of the controller card.

    In the DLL-mark of the GUI-user-program routine now everything works fine - without using "SetCtrlVal!"

    In my GUI, there is a text box of the info/comment for messages. If I do a few outputs user using 'SetCtrlVal' I always errors, caused by the false "TYPE_THREAD_FUNCTION_PARAMETERS"-values in the service of thread. "» If I set a breakpoint at the beginning thread-function I see mostly erroneous values in my transfer structure variables. If I put a breakpoint in the thread-function-calling 'CmtScheduleThreadPoolFunction (...)"and at the beginning of the thread values are (mostly) correct!

    I tried several and different things - but:

    If I ONLY (!)  Commenting on the (!) of a line with "SetCtrlVal", the program works, all States are asked out of the DLL.

    If I replace the "SetCtrlVal" with a written record-file function clean everything works fine and after completing the program I can look at the log file and see all the user information. BUT with 'SetCtrlVal' instead or set or (...) it does not work.

    My description is maybe not entirely clear, but believe me: only ONE line the «SetCtrlVal "line - should be commented out to let the program run properly!»

    Because if the line "SetCtrlVal"is program-user-GUI, after the call to the thread in the DLL, the DLL-memory seems to be corrupted by the call "SetCtrlVal" in the user-GUI program.»

    Best regards

    F.

    There may be a problem in your structure that your variable is set.

    You said that, after the address of the variable in the thread function the appellant one ends. Now, as you can read help each value passed in parameter threadFunctionData of the layed function must point to an area of memory that persist when the fuction is running: If your variable is defined at the level of the functions it is not valid when the thread runs since the appellant finished and released its local memory.

    Your approach with a global variable is a valid alternative, but if it is the solution, you will find data passed to the thread function must be valid for all his life.

  • AS3 two buttons for the same function?

    I have the next scenerio, a main.swf that loads SWFs on top, the code below

    Stop();

    var Xpos:Number = 0;
    var Ypos:Number = 0;
    var swf:MovieClip;
    var loader: Loader = new Loader();

    var defaultSWF:URLRequest = new URLRequest("swfs/home.swf");

    Loader.Load (defaultSWF);
    Loader.x = Xpos;
    Loader.y = Ypos;
    addChild (loader);
    ////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////
    Function universal BTNS
    function btnClick(event:MouseEvent):void {}


    SoundMixer.stopAll ();
    removeChild (loader);
    var newSWFRequest:URLRequest = new URLRequest ("SWFs /" + event.target.name + ".swf");
    Loader.Load (newSWFRequest);
    Loader.x = Xpos;
    Loader.y = Ypos;
    addChild (loader);
    }

    Enter btn
    /*
    btn_enter.addEventListener (MouseEvent.CLICK, btnEnterClick);

    function btnEnterClick(evt:MouseEvent):void
    {
    gotoAndPlay (2)
    }
    */

    Listeners of BTN
    home.addEventListener (MouseEvent.CLICK, btnClick);
    about.addEventListener (MouseEvent.CLICK, btnClick);

    press_.addEventListener (MouseEvent.CLICK, btnClick);
    contact.addEventListener (MouseEvent.CLICK, btnClick);
    blog.addEventListener (MouseEvent.CLICK, btnClick);
    dresses.addEventListener (MouseEvent.CLICK, btnClick);
    rompers.addEventListener (MouseEvent.CLICK, btnClick);
    separates.addEventListener (MouseEvent.CLICK, btnClick);

    I need to call the dresses of another button that is on the scene, but I can't cite the dresses of button that I already used name and the swf file is called dresses. How can I get a second call button the .swf of dresses within the same service.

    I have a feeling I'll need to add another auditor evenrt and another function to run this, if so call a second charger with the same arameters than the first?

    If I could have this release, it would be useful that a simple Yes or no won't teach me if I run again on this scenerio.

    THX

    RD

    Use the code that I have suggested.  you are declaring newSWFRequest twice which causes this error.  check my code more carefully.

Maybe you are looking for