-
1. Re: How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)
kglad Mar 3, 2010 11:36 AM (in response to Me2LoveIt2)you can only stop a for-loop using a "break" keyword. additionally, it makes no sense to try and stop a for-loop like the one you showed.
that for-loop (if it executes), defines listeners for interactive objects. that will complete long before any object is clicked.
-
2. Re: How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)
Me2LoveIt2 Mar 3, 2010 12:46 PM (in response to kglad)kglad wrote:
that for-loop (if it executes), defines listeners for interactive objects. that will complete long before any object is clicked.
Well yes but it does it again and again (frames per second times seconds = number of times it goes through the code if i'm not mistaken), because it is inside a function, and through testing i found out that it works like this:
Example:
there are 5 my_mc's in my project: (my_mc_0, my_mc_1, my_mc_2, my_mc_3, my_mc_4)
if i click my_mc_0 function#2 is called and executed. BUT only after the loop finishes (i know this from tons of testing)...which is unnecessary since you cannot click two places at once. This might not be a problem in this example because i am only using 5 my_mc's buy if i use 500000000 my_mc's it would make a lot of difference.
is there a way to stop the loop if the function is called?
...maybe there is a better way to write it, the only alternative i know that works is if i manually write every single listener and this also is logical in this example but as i said next to impossible if the numbers get bigger.
-Note
I didn't specify this earlier but function#2 makes the if statement false so it wont jump back into it.
Thank you for the help I really appreciate it!
3rd edit...don't know what's wrong with me
-
3. Re: How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)
Ned Murphy Mar 3, 2010 1:28 PM (in response to Me2LoveIt2)I don't see the sense in having the ENTER_FRAME listener involved. You are worried about doing it for 500000000 mc's... What about repeating it for 500000000 mc's at the frame rate of the file?
In the end, if you can change that loop-stopping-variable within the time it takes to complete the loop, and test that variable during each cycle of the loop, using it to call a break; command, then it can probably work for you.
-
4. Re: How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)
Me2LoveIt2 Mar 3, 2010 2:43 PM (in response to Ned Murphy)Thank you for your response,
It's still not quite what I need. Lets me make another example which has the exact same problem:
Code:
var xx; my_mc_0.addEventListener(MouseEvent.CLICK, function#1); if(the above statement temp = 0) my_mc_1.addEventListener(MouseEvent.CLICK, function#1); if(the above statement temp = 1) function function#1(e:Event):void{ xx = this["my_mc_"+String(temp)].x; }I need a way to distinguish which my_mc_# is clicked.
(is it possible to pass in a variable?) and ( can i return one?) ~ Now i realize that void generally means there is nothing to return, but can i pass a value by reference?)
Thanks again for all the help!
-
5. Re: How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)
kglad Mar 3, 2010 3:59 PM (in response to Me2LoveIt2)you can determine which object dispatched the event by using e.target or e.currentTarget. and, it doesn't make sense to return anything to a listener.
just what are you trying to do? click on one of a large number of objects and do and/or determine what?
-
6. Re: How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)
Me2LoveIt2 Mar 3, 2010 6:19 PM (in response to kglad)Thank you so much!
Yes e.currentTarget does what I want.
I want to copy the clicked objects location(x, y) and a couple of previously assigned variables into global temp variables. This is something like "selection".
Thank you again!
-
7. Re: How can I check if a function is or is not called from the event listener? in Flash CS4 (AS3)
kglad Mar 3, 2010 7:35 PM (in response to Me2LoveIt2)you're welcome.


