9 Replies Latest reply: Mar 29, 2012 7:49 AM by Natalie Butler RSS

    Multiple timeout objects (object declaration problem?)

    Natalie Butler Community Member

      So what I'm trying to do here is create 4 separate timeOut objects that are each applied to 4 different sprites. Each has a variable for the duration that is set to 0 by default so that it does not even check to call the timeout handlers. When the user clicks on a sprite, the variable associated with that sprite's related timer duration is set to 5 seconds. When that timer runs out, the handler that is called stops the timer, resets the duration variable of the timer to 0, and changes that particular sprite's image.

      Essentially, I want it so that the user can click each individual sprite and have each sprite change its image 5 seconds after that specific sprite was clicked.

       

      While my code is probably repetitive and clunky, it seems like it should work to me - but I am no expert by far. It compiles fine, but when it runs, I get this message:

       

      Script error : Object expected

      timer1 = timeOut().new("timer1", timeoutDuration1, #timeOut1, me)

       

      What exactly did I do wrong? I'm assuming it's some kind of simple syntax error but I can't figure out what. I've tried changing the name of the timer objects, setting them as global properties, etc., all I can think to do, but I can't figure it out. Or am I doing it entirely wrong altogether? Thank you SO much to anyone who can provide help.

      My code is below.

       

      -----

       

      property spriteNum, pMySpriteRef

      property timeOut1, timeOut2, timeOut3, timeOut4

       

      on beginSprite me

       

        timeoutDuration1 = 0

        timeoutDuration2 = 0

        timeoutDuration3 = 0

        timeoutDuration4 = 0

       

        timer1 = timeOut().new("timer1", timeoutDuration1, #timeOut1, me)

        timer2 = timeOut().new("timer2", timeoutDuration2, #timeOut2, me)

        timer3 = timeOut().new("timer3", timeoutDuration3, #timeOut3, me)

        timer4 = timeOut().new("timer4", timeoutDuration4, #timeOut4, me)

       

      end

       

       

      on enterFrame me 

       

        if (_mouse.clickOn = me.spriteNum) then

          pMySpriteRef = sprite(me.spriteNum)

       

          if pMySpriteRef = 1 then

            timeoutDuration1 = 5000

          else if pMySpriteRef = 2 then

            timeoutDuration2 = 5000

          else if pMySpriteRef = 3 then

            timeoutDuration3 = 5000

          else if pMySpriteRef = 4 then

            timeoutDuration4 = 5000

          end if

       

        end if

       

      end

       

       

       

      on timeOut1 me

        timeOut("timer1").forget()

        timeoutDuration1 = 0

        sprite(1).member = "Jellyfish_new_1"

      end

       

      on timeOut2 me

        timeOut("timer2").forget()

        timeoutDuration2 = 0

        sprite(2).member = "Jellyfish_new_1"

      end

       

      on timeOut3 me

        timeOut("timer3").forget()

        timeoutDuration3 = 0

        sprite(3).member = "Jellyfish_new_1"

      end

       

      on timeOut4 me

        timeOut("timer4").forget()

        timeoutDuration4 = 0

        sprite(4).member = "Jellyfish_new_1"

      end