the callback function of Event.COMPLETE is not always called.
for example,the max value of count is 62, 64 or 65
function Player:onAddedToStage()
for i = 1, 100 do
local mc = MovieClip.new{
{1, 10, self}
}
mc:addEventListener(Event.COMPLETE, self.complete, self)
end
end
local count = 0
function Player:complete()
count = count + 1
print(count)
end
Comments
and since count = count + 1 is not an atomic function, many of the complete callbacks use same value of count and increase it, and not increased value by previous complete.
Here's an example:
First complete ended, it takes count (which is 0), second complete ended, it also takes count which is 0, first complete increases count by one and saves it into count variable, which is now 1.
Second complete increases it's own count value (which is 0) and saves it to same variable first complete saved, overriding the value (it saves 1 again).
So two complete's ended, but count was increased only by 1.
You need to think more multi thread-alike, event driven to measure it.
For example:
In fact, in @alexzheng example, while executing the loop, some of the movie clips are garbage collected so that Event.COMPLETE event is not dispatched for them.
@ar2rsawseen you can think that everything works in a single-threaded environment. (and in fact it is)
as @atilim said some of the movie clips are garbage collected, I will try to reference the mc in the player.
self.mc = mc -----add this line
is that OK?
function Player:onAddedToStage()
local mc = MovieClip.new{
{1, 10, self}
}
self.mc = mc -----add this line
mc:addEventListener(Event.COMPLETE, self.complete, self)
end
function Player:complete()
--do something
self.mc = nil
end
https://sites.google.com/site/xraystudiogame
Will MovieClip.pauseAll() and MovieClip.resumeAll() be available in next version?
And currently, does mc:stop reset the current frame or just pause at current frame and mc:play resume from current frame?
https://sites.google.com/site/xraystudiogame
Also if I modify your code as:
mc:stop pause at current frame and mc:play resume from the previously paused frame.
I also think about adding the mc to a table,and stop all the mc in the table on pause,but I can not determine which mc to remove from the table in the complete function.
https://sites.google.com/site/xraystudiogame
finally,I just search all the children to get the mc and stop it on pause.
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame