3 Replies Latest reply on May 18, 2006 12:24 AM by slawu

    Synchronisation

    slawu
      Hi,
      I would like to know if there is some method of synchronisation of threads in Flash.
      I found one topic in the archives of this forum about threads in Flash. Someone said that
      there is only one thread in Flash but... When I use setInterval() the code is executed
      asynchronously. The same happens with event handlers, with the code put in the timeline etc.
      So there must bu some way of synchronising events.

      For example I would like to load some external movie (with loadMovie()) and wait for it to initialize.
      I would like to wait (put my action script on hold) until something happens in some other movie clip.
      Is there a way to sleep for some time or wait on some semaphore or to yield?
        • 1. Re: Synchronisation
          TimSymons Level 1
          It sounds like (and I'm only guessing here) that you need to you event listeners in your code. For example, the MovieClipLoader class dispatches events when a movie starts loading, while loading, when finished loading, and finally when the movie has be initialized and accessible to actionscript. These are all talked about in the Help files with good examples.

          You can also add your own event dispatching to your code by using the mx.events.EventDispatcher class.

          Is this what you were looking for?

          Tim
          • 2. Re: Synchronisation
            Level 7
            >> Someone said that there is only one thread in Flash but...

            But or no, there is only one thread.

            >> When I use setInterval() the code is executed asynchronously.
            >> The same happens with event handlers, with the code put in
            >> the timeline etc. So there must bu some way of synchronising
            >> events.

            Sounds like you've described it.

            > You can also add your own event dispatching to your code
            > by using the mx.events.EventDispatcher class.
            >
            > Is this what you were looking for?

            Tim nailed it. Since there is no sleep() function in ActionScript, so
            you can modularize your code and run what you need based on events. I
            recently blogged on EventDispatcher and AsBroadcaster, so if it's any help
            to you, check out ...

            http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-asbroadcaster
            http://www.quip.net/blog/2006/flash/actionscript-20/how-to-raise-events-eventdispatcher


            David
            stiller (at) quip (dot) net
            Dev essays: http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: Synchronisation
              slawu Level 1
              Thanks a lot for help! I'll read some more on this topic and then... maybe I'll have more questions. Thanks