arguments of a function addEventListener

public function getUser (): void
{
var i: Number;
for (i = 0; i<>
{
red.addEventListener (MouseEvent.MOUSE_UP, addEntered (0));
blue.addEventListener (MouseEvent.MOUSE_UP, addEntered (1));
yellow.addEventListener (MouseEvent.MOUSE_UP, addEntered (2));
green.addEventListener (MouseEvent.MOUSE_UP, addEntered (0));
}
}

Im getting an error saying "1067: Implicit coercion of a value of type void to a type unrelated to function."

IM assuming that I can't pass a parameter there?

The objective of this piece of code is tuned for a mouse up on these colors and depending on whether one is clicked, go 0,1,2 or 3 to the function addEntered(num:Number): void

I'm not expert AS3, but it seems that you try to enter a number in a function that accepts only events.

Your function is to be "funcName(event:MouseEvent)".

red.addEventListener (MouseEvent.MOUSE_UP, funcName);

You can make a separate function which is fed the MouseEvent that calls your function addEntered:

So if you give your attributes of color (via a custom class that extends MovieClip, perhaps) buttons, you can feed these numbers in your addEntered function using "event.target.someAttribute".

Something like:

-----

red.someAttribute = 0;

blue.someAttribute = 1;

yellow.someAttribute = 2;

green.someAttribute = 3;

red.addEventListener (MouseEvent.MOUSE_UP, colorListener);
blue.addEventListener (MouseEvent.MOUSE_UP, colorListener);
yellow.addEventListener (MouseEvent.MOUSE_UP, colorListener);
green.addEventListener (MouseEvent.MOUSE_UP, colorListener);

{colorListener(event:MouseEvent):void}

var num:Number is MovieClip (event.target) .someAttribute;.

addEntered (num);

}

-----

This also allows you to avoid using a loop for, which are annoying and it doesn't make sense to me in this case anyway.

I can't say this will work for you, and is certainly not complete code. As3 experts confirm that I am on the right track here?

Tags: BlackBerry Developers

Similar Questions

  • Is it possible to pass an argument to the function triggered by an event handler?

    Hi all
    Try to migrate my way of thinking in AS2 to AS3/CS4.
    OK, I have 2 buttons on the stage. Each button almost did the same thing, so I want to create a unique function, and each button calls this function even (we'll name this function 'Navigate')... However, the function will have to end up doing something different dependent on which button was clicked.
    If, previously, in AS2, I would have added the code on the buttons themselves with methods we (release) (see the SAMPLE CODE 1)

    Thus, each button calls the function efficiently navigate and transmits a different image to the function tag.
    Now, I try to recreate this feature in AS3. As you know, it (release) has been abolished (still do not know why), but we must now use event handlers, so I'll try to find a way to pass a different image to the function label argument to navigate. Currently, I can achieve that by using a switch statement to test which button has been clicked and act accordingly (see the SAMPLE CODE 2).

    In this simplistic example, this works very well, but in the real world, I have more than 2 buttons and the function navigate would probably much more complicated...
    So I would be able to pass an argument (as in the AS2 example) to the function to navigate... maybe in the addEventListener() method? I tried, but got compile errors (see the EXAMPLE CODE 3):

    The issue of the $ 1 Million:
    Is it possible to pass/change dynamically an argument to a function that is triggered by an event listener? (Or is the event that triggered the function the only argument you have?)
    If this is not possible, I would like to hear how you people it would handle (other than to have a switch with 12 cases in there)?

    I found a few solutions that I'll post below for prosperity...

    You can create a dictionary indexed by the targets of future events and store information in there you want to associate with them. Then the Navigate function check that the dictionary to get its parameters:

    Code.
    Button1.addEventListener (MouseEvent.CLICK, navigate, false, 0, true);
    Button2.addEventListener (MouseEvent.CLICK, navigate, false, 0, true);

    var buttonArgs:Dictionary = new Dictionary();
    buttonArgs [Button1] = "FrameLabel1";
    buttonArgs [Button2] = "FrameLabel2";

    function Navigate(e:MouseEvent):void {}
    gotoAndStop (buttonArgs [e.target]);
    }

    This to me, is about the same amount of work than writing a long, but a bit more elegant switch statement, I guess.

    I had a little trouble understanding the following solution, because I did not quite understand important information about event listeners. The addEventListener () method requires a function as the 2nd argument passed to it.
    It didn't quite click on until someone reminded me: Navigate is a function... Navigate("FrameLabel1") is a callfunction...

    So by writing simply navigate, I'm not actually calling the function when calling the addEventListener method, I'm just providing the event with a reference the name listener. Then, when the listener is triggered, the listener will call (and pass a MouseEvent argument to) navigate the function.

    Conversely, by writing Navigate("FrameLabel1") as 2nd argument, the event listener trys to run the function navigate both the addEventListener method is instantiated. And, since then, in this example, the function navigate returned as ": Sub" a compilation error would occur because as I said, an event listener requires a function as 2nd argument data type. This would be essentially as written addEventListener (MouseEvent.Click, Sub, false, 0, true)
    However, there is a way to get around this... basically, instead of setting the function navigate as returning an empty data type, you define a function to return data type and then nest another function (which actually contains the actions you want to run) on the inside.

    Button1.addEventListener (MouseEvent.CLICK, Navigate ("FrameLabel1"), false, 0, true);
    Button2.addEventListener (MouseEvent.CLICK, Navigate ("FrameLabel2"), false, 0, true);

    function Navigate(myLabel:String):Function {}
    return function(evt:MouseEvent):void {}
    gotoAndStop (myLabel);
    }
    }

  • Chr (44) to replace the commas separating the arguments of a function?

    In Oracle SQL, it is possible to replace the commas between the arguments of the function with chr (44)?  A simple example with substr():

    substr ("yyyy", 1, 1) - the result is 'a '.

    vs

    substr ("aaaa" chr (44) 1 chr (44) 1)-this should also return 'a '.

    Is there a way to make the second example works the same way as the first?  I tried different techniques escaping, string concat, etc., and I failed.  Is there a method to replace the comma (",") the character of the way I'm looking for or is this impossible?

    Thank you

    N °

    The Analyzer seeks commas, not for other things you as a human being assimilated by a comma.

  • Impossible to find a way to put a property as an argument to a function

    Hello

    I have not found a way to put a property (position, anchorPoint etc.) as an argument to a function.

    I tried:

    It is a function inside a loop.

    function loopArray (theArray, layers, theProp, n) {}

    for (var j = 0; j < theArray.length; j ++) {}

    layers [n].theProp.setSelectedAtKey (parseInt (theArray [j]), true);

    }

    }

    for (var i = 0; i < layers.length; i ++) {}

    loopArray (anotherArray, someLayers, AnchorPoint, i);

    }

    He does ' t work.

    THX in advance

    Candos

    I think you have pass the property name, which might work in simple cases (such as the "anchor"), either:

    function loopArray (theArray, layers, thePropName, n)) {}

    ... layers [n] .property (thePropName) .setSelected...

    ... loopArray (UnAutreTableau, someLayers, "Anchor", i);

    Better yet, in my opinion, would be to pass an array of properties:

    var thePropArray = [];

    for (var i = 1; i)<= mycomp.numlayers;="">

    thePropArray.push (myComp.layer (i) .property ("anchor"));

    }

    Call your function.

    Something like that.

    Dan

  • Closure on the arguments of a function

    I know it must be simple, but I'm apparently not find good Google search terms.

    I have a function called foo, in which I want to pass any number of arguments.  Each argument will be the name of a page element.

    For example: foo ('P21_CUST_NAME', 'P21_CUST_CITY', 'P21_CUST_ZIP');

    I want to iterate (loop) over the arguments and values of each test item.    Foo will return a string like. y.n.y. that will be searched to find all occurrences of. n. If all occurrences of. n. lie, then the page is not fully completed, and I'll show you a red icon.

    I want to build this as a multi-purpose function that can accept a number any arguments.  The logic in the loop (i.e. null or not) is not at issue here.  I can do it without problem.  I just need to know how a loop on all of the arguments passed in foo, if there is an argument, or three or twenty-seven.

    Thoughts, please?

    Apex 4.2.3.00.08

    Mark T. says:

    I was unclear in my use of the word "function".  I want to define a function in JavaScript, not PL/SQL.

    In this case, iterate over the elements of the arguments object:

    function foo () {
      for (var i = 0; i < arguments.length; i++) {
        alert(arguments[i]);
      }
    }
    
  • arguments of a function

    Hi there.
    is a way to get the arguments for the function onFinishTween? (for event onComlete)
    TweenLite.to(MC, 1.5, {alpha:1, tint:color[Math.floor(Math.random()*(color.length))],onComplete:onFinishTween});
              function onFinishTween():void {
                             //trace("The tween has finished! b-) ");
                             //reNew();
                        }
    

    I want to cheack all finieshfunction;
    Thank you very much

    You are welcome.

    p.s. If you're still able, please mark this thread as answered.

  • What does '... argument ' average in the arguments of a function

    So can someone explain this?

    So far, I have seen no document on this subject. I don't know how to use it, but I would like to know what it means and.

    Things like these makes the flash/flex/as learning reylly hard when there is no documentation.

    If you define a function, you can add... .args as argument, which means that the function can receive an array of multiple arguments. This is useful if you don't know in advance of the arguments how your function will receive.

    An example:

    public void sum(...args):Number

    {

    var s:Number = 0;

    for each (var n: Number in args)

    {

    s += n;

    }

    return s;

    }

    See also: http://www.adobe.com/livedocs/flex/2/langref/statements.html#..._%28rest%29_parameter

    Dany

  • Problem with the arguments of a function

    I'm having a problem with the arguments of a function does not. In the attached example, the values passed to the function never appear within the function.

    Can someone tell me what I am doing wrong?

    Thank you
    David

    * the params in your displayPic function should be only by var, not their names name var and their data types *.

    Copy and paste the code I wrote below in a new flash on chassis of the _root document, follow the code, test the movie and check your output window. you will see how to pass arguments to a function is as simple as 1, 2, 3.

  • function addEventListener references child in movieclip. How can I stop this?

    I built a custom designed checkBox. The movieclip in the library and drag on the chronology of my .swf. I use CS4 & AS3. I use procedural AS3 rather than OO AS3.

    The box movieclip a child movieclip inside so I can apply a filter drop shadow to some of the graphics.

    When I put an eventlistener on the custom checkbox it works fine, but when I try to reference the movieclip checkbox inside the eventlistener function, the event.target.name refers to the child movieclip (just a chart with a drop shadow filter).

    From my reading, it looks like to the spreading function down to the child movieclip, but I don't want to do that.

    How do I

    A. reference the parent movieclip?

    or

    B. stop the eventlistener of reproducing down to the child movieclip?

    I tried to use stopPropagation(); but it did not prevent the function of runoff event.target.name down to the child movieclip.

    Here's what looks like AS3.

    The statement displays trace "step3_mc.cbEmail_mc.instance25" instead of what I need "step3_mc.cbEmail_mc".

    step3_mc.cbEmail_mc.addEventListener (MouseEvent.CLICK, fnc_cbClick);
    step3_mc.cbAgree_mc.addEventListener (MouseEvent.CLICK, fnc_cbClick);

    function fnc_cbClick(event:MouseEvent):void {}

    trace ("fnc_cbClick:" + event.target.name + "" + event.target.currentFrame);

    If (event.target.currentFrame < 3) {event.target.gotoAndPlay ("cbOn") ;} else {event.target.gotoAndPlay ("cbOff") ;}
    }

    Use event.currentTarget.name to get the name of the desired instance (which is the instance assigned to the event listener). If you use event.target.name, the name of the instance, hence the click origin is traced, which may or may not be what you want.

    TS

  • ORA-00600: internal error code, arguments: [17012] with function pipeline

    The package is containing a type of function and the table declaration.
    the function returns the type of the collection is in pipeline

    When I recompile the plu sql package I get this error
    ORA-00600: internal error code, arguments: [17012].

    Hello!

    There is a known bug 2280512. But this info is no longer valid for version 9.2 of the db... If this is the case (you have'n give your version of db) you need to pass your database to a higher version (9.2.0.8 is good enough confirmed of my practice)

    T

  • a reminder of the user interface will have a function with arguments?

    some ScriptUI quirks... I have a function (cut in this example) that I can call very well by itself of the extendScript window or if I set directly to the onClick callback, but when I try and call the function from a reminder and analyze arguments, the onClick is not working and the service runs once when the script runs first? what I am doing wrong?

    It works using the extend script window

    Nudge (23,77)


    function nudge (offset, distance) {}

    var L = app.project.activeItem.selectedLayers [0];

    L.startTime = (shift * distance);

    Alert ("Done")

    }

    This works when the button is clicked in the user interface


    myButton.onClick = function() {

    var L = app.project.activeItem.selectedLayers [0];

    L.startTime = (23 * 77);

    alert("done")

    }

    This also works when the button is clicked in the user interface


    myButton.onClick = boost


    function nudge() {

    var L = app.project.activeItem.selectedLayers [0];

    L.startTime = (23 * 77);

    alert("done")

    }

    but when I try and pass arguments (kind of functions) that does not


    myButton.onClick = nudge (23,77)


    function nudge (offset, distance) {}

    var L = app.project.activeItem.selectedLayers [0];

    L.startTime = (shift * distance);

    Alert ("Done")

    }

    OK, in the case where someone is interested... the solution with the permission of Mr. Lloyd Alvarez is to nest the function in another function call, why, I have no idea, but it works a treat...

    myButton.onClick = function() {nudge (23,77)}

    function nudge (offset, distance) {}

    var L = app.project.activeItem.selectedLayers [0];

    L.startTime = (shift * distance);

    Alert ("Done")

    }

  • two or more arguments to a javascript function

    I develop my application using APEX 3.2.1.00.12
    In the properties of a Page, I have this:
    < script language = "JavaScript" type = "text/javascript" >

    function j_elimina_att (vpar) {}

    var id_canc = document.getElementById ('P30_SEQID_COLLATT_DEL');

    id_canc. Value = test;
    doSubmit();
    }

    < /script >

    Then I call the fuction this way:

    JavaScript:j_elimina_att('#ID_RIGA#');

    Now, I want to assign two or more items, not only P30_SEQID_COLLATT_DEL.
    Is this possible?
    How can I write the arguments in the function definition and the call?
    Thank you

    Hello

    Example of

    
    

    And you call JavaScript example

    javascript:j_elimina_att('#ID_RIGA#','#COL_2#');
    

    PS: see document Apex JavaScript API
    http://download.Oracle.com/docs/CD/E14373_01/apirefs.32/e13369/javascript_api.htm#CDEEIGFH
    You can find for example this $s function that I used as an example

    Kind regards
    Jari

  • Using variables for the AS2 function arguments

    Hello

    I am trying to create a function in AS2.

    After you create the function, I want to use the values stored in the variables specified for the arguments to the function instead of manually typing static values for the calculation of the service. Also, I want to use the function to assign a new value to the existing variable.

    I asked a similar question here 2 days ago and got the answer (thanks), but now I have another question - how to create the function to assign a value to the variable, the variable itself is also a function argument?

    For example, I have 6 numeric variables:

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;

    var CoinD:Number = 30;
    var CoinE:Number = 40;
    var CoinF:Number;

    Then I tried to create a function to assign values to the variables stuck and CoinF:

    function CalculationA(FirstCoin,_SecondCoin,_ThirdCoin):Void {}

    FirstCoin = SecondCoin + ThirdCoin;

    }

    CalculationA (stuck, CoinA, CoinB);
    CalculationA (CoinF, stuck, CoinF);

    The code above didn't really affect the values of 30 and 70 stuck and CoinF variables, but instead, stuck and CoinF values are undefined.

    Please give me the correct code if there is a good way to do this.

    Thank you

    Here's a way to do it, passing a string value with the name of the variable instead of the actual variable name...

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;
    var CoinD:Number = 30;
    var CoinE:Number = 40;
    var CoinF:Number;

    function CalculationA(FirstCoin,_SecondCoin,_ThirdCoin):Void {}
    This [FirstCoin] = SecondCoin + ThirdCoin;
    }

    CalculationA ('stuck', CoinA, CoinB);
    CalculationA ("CoinF", CoinD, person);

    (Note that in your second function call, I changed coins since CoinF (ThirdCoin) is not defined at this time).

  • Using variables for an AS2 function arguments

    Hello

    I am trying to create a function in ActionScript 2.

    After you create the function, I want to use the values stored in the variables specified for the arguments to the function instead of manually typing the static values for the arguments to the function. And also I want to use the function to assign a new value to the existing variable. Is this possible?

    For example, I've defined variables "here is a simple function named"CalculationA".

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;


    function CalculationA (CoinA, CoinB, stuck) {}

    Stuck = Number (CoinA) + Number (CoinB);

    }

    The code above does not really. No value is assigned to the variable stuck.

    Can someone give me a good AS2 code please?

    Thank you

    use:

    var CoinA:Number = 10;
    var CoinB:Number = 20;
    var CoinC:Number;

    CalculationA (CoinA, CoinB);

    function CalculationA(coinA,_coinB):Void {}

    Stuck = Number (coinA) + Number (coinB);

    }

  • Number of arguments passed to the count function

    There are built-in functions that can count the number of arguments passed to a function? Obviously (arguments) StructCount doesn't work here because "the scope always contains an entry 'slot' for each argument declared, even if you do not pass the argument to the function.»

    Copy the following code always returns "Count = 3 '. I want to output 'Count = 1' because the only argument has been passed to the function. The functions of any integrated to do this or am I stuck do manually: a loop + structKeyExists?

    < cfset comp = createObject ("component", "MyComp") >
    < cfset comp.showArgs (id = 1) / >

    <! - MyComp - >
    < cfproperty >
    < cffunction name = returntype "showArgs" = "Sub" output = "true" >
    < name cfargument = "id" type = "numeric" required = "true" / >
    < name cfargument = "FirstName" type = "string" required = "false" / >
    < name cfargument = "name" type = "string" required = "false" / >
    Count = < cfoutput > #StructCount (arguments) # < / cfoutput > < br >
    < / cffunction >
    < / cfproperty >

    Thanks for the replies.

    My question was not so much about how it works. I understand that CF always adds a slot in the structure of optional arguments. Maybe its just me, but it seems a bit logically inconsistent to return different results of StructCount (etc.) and StructKeyExists? If StructCount "counts the number of keys in a structure" then StructKeyExists should behave in accordance with the StructCount, but it doesn't. I understand why its done in this way, but it still seems a bit inconsistent.

    In any case, because there isn't a built-in method to return only the arguments provided, I ended up doing manually as I've described before.

Maybe you are looking for