Adding a listener to an array?
- Halosheep
-
Halosheep
- Member since: Apr. 9, 2009
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
How do you do it? I know you can add an Event Listener to a specific object like so
objectName.addEventListener(Event.ENTER_FRAME, function);
But if I try to do it for an array like so
var sampleArray:Array = new Array;
sampleArray.push(objectName);
sampleArray.addEventListener(Event.ENTER_FRAME, function);
I get an error
TypeError: Error #1006: addEventListener is not a function.
at Selection_fla::MainTimeline/frame1()
Thanks in advance for any help you guys can provide
"If everyone did things 75% right people would be ecstatic, so I demand that you change this C to an A+!" - Calvin and Hobbes
- milchreis
-
milchreis
- Member since: Jan. 11, 2008
- Offline.
-
- Forum Stats
- Member
- Level 26
- Programmer
Apply the listener to an item of the array, not the array itself.
- Halosheep
-
Halosheep
- Member since: Apr. 9, 2009
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
The point was that I need it to be applied to all the objects in the array. For some reason, you made me think of a very roundabout way of doing this, by making another function with a loop in it which cycles through the array and adds the listener, ect, but I was wondering if there was a more simple and direct way of doing it.
"If everyone did things 75% right people would be ecstatic, so I demand that you change this C to an A+!" - Calvin and Hobbes
- knugen
-
knugen
- Member since: Feb. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 42
- Programmer
A loop is practically just one more line of code :)
- Halosheep
-
Halosheep
- Member since: Apr. 9, 2009
- Offline.
-
- Forum Stats
- Member
- Level 05
- Blank Slate
Not efficient enough lol
Kidding, but I was curious if it was possible anyways. I have it working now, but thanks for the reponses
"If everyone did things 75% right people would be ecstatic, so I demand that you change this C to an A+!" - Calvin and Hobbes
- milchreis
-
milchreis
- Member since: Jan. 11, 2008
- Offline.
-
- Forum Stats
- Member
- Level 26
- Programmer
It's probably not a good idea to have one enter frame for each object.
You rather want to have one enter frame that iterates over the objects.
However, that's probably something to be considered "useless information nobody cares about" as I know this forum...
- Redshift
-
Redshift
- Member since: Feb. 12, 2005
- Offline.
-
- Forum Stats
- Member
- Level 15
- Programmer
At 10/11/10 04:58 PM, milchreis wrote: It's probably not a good idea to have one enter frame for each object.
You rather want to have one enter frame that iterates over the objects.
However, that's probably something to be considered "useless information nobody cares about" as I know this forum...
It's faster, and more predictable. Good enough for me.
#include <stdio.h>
char*p="#include <stdio.h>%cchar*p=%c%s%c;%cmain() {printf(p,10,34,p,34,10);}";
main() {printf(p,10,34,p,34,10);}

