1 Reply Latest reply on Oct 23, 2009 7:02 AM by wbpit

    Wait problem after animation

    wbpit

      Hi,
      I got now a similar problem like hundreds of other users (searching the forum with keyword „wait“). Most of them were satisfied with the solution to use the setinterval.
      But I didn’t find any suitable solution for my problem.
      Is there anybody who could help me?
      My Flash Project  (AS 2.0) should represent a cardgame.
      I divided this in the following sections.
      In the maintimeline a menu is handled like „new game“, „Rules“ and so on.

       

      The first class represents the game leader „gameleader“. This class is responsible to know how the game should going on depending on different events, cards and inputs of the PC-User, which plays against the computer.

       

      The second class „gametable“ represents the table where the game is played.
      It contains the cards, shuffling the cards and so on.

       

      The third class represents the gambler.
      It accepts the cards, save it, plays a card depending on the rules of the game, and it should show the cards on the stage (either the back or the frontside).

       

      My project is now at a point where 3 each cards are given to 4 gamblers (first round).
      Therefore some functions and methods have been called (Menu-> new, shuffle, and so on).
      At this point I wanted  the cards to be animated and I made a Transition and/or a Tweening for each card.
      The effect is that the animation starts first  when the mainmethods/functions are leaved and then all cards are animated together.
      Of course the onMotionFinished/allTransitionsInDone functions (asynchronous) are also actived when all cards were animated.
      I want that  one card appear, animates and then show the next card.
      Someone could say I should only play/animate 1 card, wait for  finishing and then show the next card.
      But I see no possibility to do so, because when the onMotionFinished/allTransitionsInDone function is activated I left my previous path and I lost my context.
      I would like to have a synchronous activation of a waitstate like a pend / unpend function.
      Do you see any solution therefore?
      Here again a short summary:

       

      Main line          Class gameleader             Class gametable               Class gambler

       

      event new ->        init  Table/gambler
                                dispatching tasks
                                depend. on rules
                                for example                  ->  shuffle cards
                                                                    -> give cards to gamblers    ->   save cards
                                                                                                                   sort etc.
                                                                                                                  show card with
                                                                                                                  animation
                                                                                                                 [ *** pend***]    --> not supported
                                                                                                             [continue <-- unpend]
                                                                 --> do anything
                                            leaving          <--
      asynchronous onMotionFinished function (eventObject:Object) 
      context from where the animation was started is lost!!!
      eventObject has only type and target

        • 1. Re: Wait problem after animation
          wbpit Level 1

          After a long time of brood on my problem, I solved it (tempor.?) in the following way (simplified):

          All the tasks(functions, methods) to be done are saved in an array.

          A Taskhandler (TH) is activated by setInterval and at the beginning of the TH immediately stopped.

          On a central place the current state of the Taskhandler is deposited.

          The TH calls methods by using the function-string at the current index of the array.

          example: var func = myArray[curindx];          // content "showCard"

                        classInstanceName or this[func] ();          // call the function

          At the end of the TH I decide by an indicator, whether a new setInterval for the TH is activated or not.

          The indicator is set or not (depending on what the called function wants to do).

          For example, if the called function wants to wait for the end of an animation the setInterval

          will be deactivated and after finishing the animation activated again.

          This is also valid using Alert (and surely for some other functions - waiting on input of RadioButtons).

          There are 2 processes. While the first one ends (TH is not activated) a new process is started handling the end

          of the animation and activate again the TH.

          The difficulties are because, there is no description how these processes work.

          (priority of interrupt, control of the interrupts).