Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Event.COMPLETE dispatched by MovieClip — Gideros Forum

Event.COMPLETE dispatched by MovieClip

alexzhengalexzheng Guru
edited March 2012 in Bugs and issues
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

Likes: aditya, Yan

+1 -1 (+2 / -0 )Share on Facebook

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited March 2012
    My guess would be the ending time for them is pretty similar if not the same
    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:
    function Player:onAddedToStage()
        for i = 1, 100 do
        local mc = MovieClip.new{
           {1, 10, self}
        }
        mc.i = i
        mc:addEventListener(Event.COMPLETE, function()
           print(self.i)
       end, mc)
     end
    end
    And see if all values from 1to 100 are printed (may not be in incremental order, though)
  • atilimatilim Maintainer
    edited March 2012
    Hi,

    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)
  • alexzhengalexzheng Guru
    edited March 2012
    In fact,in my real project the code is as following,and there are many player instances created randomly.
    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
  • Timer.pauseAll() and Timer.resumeAll() are very useful when the pause menu popup. But it's not so simple to pause all the movieclip.
    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?
  • atilimatilim Maintainer

    self.mc = mc -----add this line
    is that OK?
    totally ok.

    Also if I modify your code as:
    movieclips = {} -- added this line
    function Player:onAddedToStage()
        for i = 1, 100 do
            local mc = MovieClip.new{
                {1, 10, self}
            }
            movieclips[#movieclips + 1] = mc  -- and added this line
     
            mc:addEventListener(Event.COMPLETE, self.complete, self)
        end
    end
     
    local count = 0
    function Player:complete()
        count = count + 1
        print(count)
    end
    You should see 100 as the final count.

  • atilimatilim Maintainer
    Timer.pauseAll() and Timer.resumeAll() are very useful when the pause menu popup. But it's not so simple to pause all the movieclip.
    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?
    I will add MovieClip.pauseAll() and MovieClip.resumeAll() but most probably not to the next version. 2012.2.2 has already many items to be implemented. But I've added this two functions to the roadmap of 2012.2.3.

    mc:stop pause at current frame and mc:play resume from the previously paused frame.
  • hi @atilim
    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.
  • atilimatilim Maintainer
    Maybe you can use event:getTarget() function to obtain the mc that dispatches the event.
  • alexzhengalexzheng Guru
    edited March 2012
    what I mean is how to dereference the mc from table movieclips.

    finally,I just search all the children to get the mc and stop it on pause.
  • atilimatilim Maintainer
    You should store the movie clips like:
    movieclips[mc] = true
    and then when a movie clip finishes, you can remove it by using:
    movieclips[mc] = nil
    and you can iterate over movieclips table by using:
    for mc in pairs(movieclips) do
    end
Sign In or Register to comment.