0
Sending multiple types of variables to a function
Participant
,
/t5/animate-discussions/sending-multiple-types-of-variables-to-a-function/td-p/971333
Aug 15, 2008
Aug 15, 2008
Copy link to clipboard
Copied
Hello Community!
I know that it is possible to feed more than one variable to a function -- even if the variables are of different types (the attached code works if I take away all references to the MouseEvent; that is, if I only pass the a, b, and c variables to the function). My question is, can I make this work when I also want to pass a MouseEvent variable to the function as well? In other words, is it possible to place something in the spot where I have the "???" that satisfies the functions demand for an answer to the MouseEvent? I have tried "null", "void", and "undefined" but these do not work.
Any input would be appreciated.
-john
I know that it is possible to feed more than one variable to a function -- even if the variables are of different types (the attached code works if I take away all references to the MouseEvent; that is, if I only pass the a, b, and c variables to the function). My question is, can I make this work when I also want to pass a MouseEvent variable to the function as well? In other words, is it possible to place something in the spot where I have the "???" that satisfies the functions demand for an answer to the MouseEvent? I have tried "null", "void", and "undefined" but these do not work.
Any input would be appreciated.
-john
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/animate-discussions/sending-multiple-types-of-variables-to-a-function/m-p/971334#M26358
Aug 15, 2008
Aug 15, 2008
Copy link to clipboard
Copied
To my knowledge, event listeners expect only one parameter -
event.
If you need other parameters available to the listener - you need to either use global variables, or target's properties or you may want to write a custom event that will have custom event properties in addition to the native ones.
If you need other parameters available to the listener - you need to either use global variables, or target's properties or you may want to write a custom event that will have custom event properties in addition to the native ones.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/animate-discussions/sending-multiple-types-of-variables-to-a-function/m-p/971335#M26359
Aug 15, 2008
Aug 15, 2008
Copy link to clipboard
Copied
You can do it if you create an anonymous function your event
listener responds to.
myThing.addEventListener(MouseEvent.CLICK,
function sendMoreVars(e:MouseEvent){
moreThanOneVar(a,b,c,e)
})
Cheers,
FlashTastic
myThing.addEventListener(MouseEvent.CLICK,
function sendMoreVars(e:MouseEvent){
moreThanOneVar(a,b,c,e)
})
Cheers,
FlashTastic
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/animate-discussions/sending-multiple-types-of-variables-to-a-function/m-p/971336#M26360
Aug 15, 2008
Aug 15, 2008
Copy link to clipboard
Copied
Yes, it is one of the way of doing it but I think anonymous
functions in event listeners are not such a good idea from GC
standpoint. How does one remove it? I believe other workarounds are
more solid.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/animate-discussions/sending-multiple-types-of-variables-to-a-function/m-p/971337#M26361
Aug 16, 2008
Aug 16, 2008
Copy link to clipboard
Copied
You are correct Andrei, it would be difficult (if not
impossible) to remove this event listener. Thanks for pointing out
my mistake.
Cheers,
FlashTastic
Cheers,
FlashTastic
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ropeGun
AUTHOR
Participant
,
/t5/animate-discussions/sending-multiple-types-of-variables-to-a-function/m-p/971338#M26362
Aug 17, 2008
Aug 17, 2008
Copy link to clipboard
Copied
Andrei1,
Which other workarounds do you think are better?
Regards,
ropeGun
Which other workarounds do you think are better?
Regards,
ropeGun
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/animate-discussions/sending-multiple-types-of-variables-to-a-function/m-p/971339#M26363
Aug 18, 2008
Aug 18, 2008
Copy link to clipboard
Copied
The way you have written your code you don't need to pass
additional variables. You declared a, b, and c as global vars in
this scope - so they are readily available to the listener. Even if
their values will change - listener will capture that. Another
story will be if you attach the same listener to multiple buttons
and would like to read different variables depending on what button
is clicked - here you will need a work around. If this is the case
- please tell more about your task.
As it is now, the code should look like this:
var a:String = "a";
var b:uint = 3;
var c:Array = new Array("apples", "oranges", "kiwi");
function moreThanOneVar(me:MouseEvent):void {
trace(a);
trace(b);
trace(c);
trace(me.currentTarget.name);
};
this.myButton.addEventListener(MouseEvent.CLICK, moreThanOneVar);
As it is now, the code should look like this:
var a:String = "a";
var b:uint = 3;
var c:Array = new Array("apples", "oranges", "kiwi");
function moreThanOneVar(me:MouseEvent):void {
trace(a);
trace(b);
trace(c);
trace(me.currentTarget.name);
};
this.myButton.addEventListener(MouseEvent.CLICK, moreThanOneVar);
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

