0

I am building a framework for loading minigames (in swf), and am running into a problem.

I currently have a listener that listens for events that the child minigame sends to the parent framework. However, if the child sends two messages (events) too close to each other, it seems that the first event simply get ignored, which causes some of the messages not to reach the parent framework at all.

I read that you can queue up actionscript events somehow, so that events are processed in a FIFO basis. How can I do that? Documentation seems to be pretty scarce for this issue, so I am stumped.

Many thanks!

futureelite7
  • 11,462
  • 10
  • 53
  • 87
  • 1
    hmmm ... this is REALLY strange ... AVM2 is single threaded ... if you dispatch an event, then ALL handler functions are called before execution continues ... could you narrow it down and post a minimum setup to reproduce the problem? greetz back2dos – back2dos Jun 03 '09 at 16:53
  • Ya, it definitely sounds like there is something else going on here. Perhaps post your event dispatch code, and explain the structure a little. Are they being dispatched from the same place in the same way? – Tyler Egeto Jun 03 '09 at 20:08
  • On further investigation, it seems that I dispatched an event that killed the child swf before it has a chance to send the other message (since AVM2 is single threaded). So problem solved! Thanks for your help. – futureelite7 Jun 04 '09 at 02:06

1 Answers1

2

You should really post code with questions like this; the others are right -- it does sound like you've made a mistake somewhere, and it's a lot easier to help with these kinds of problems when they're accompanied by some code.

That said, even if you dispatched your events in a tight loop, like this:

addEventListener("foo", handleFoo, false, 0);

for (var i:int = 0; i < 100; i++)
{
   dispatchEvent(new FlexEvent("foo"));
}

private function handleFoo(event:Event):void
{
   trace("hello");
}

... you'd see as many "hellos" as iterations of that loop; it doesn't get much "closer together" than that. You can prioritize event handling -- e.g., this listener gets called first (hence the "0" above), this other listener gets called second ("1"), and so on -- using the priority argument of the addEventListener function (again, see above), but that's about it. There's no built-in queueing of event dispatching unless you write the queue yourself.

Christian Nunciato
  • 10,276
  • 2
  • 35
  • 45