Skip navigation
Natalie Butler
Currently Being Moderated

Multiple timeout objects (object declaration problem?)

Mar 27, 2012 7:38 PM

Tags: #timeout #object #timer

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

 
Replies
  • Currently Being Moderated
    Mar 27, 2012 8:05 PM   in reply to Natalie Butler

    I can't imagine what you have that code attached to. Why don't you try something like the following, attached to each individual sprite:

    property spriteNum
    property my
    
    on beginSprite me
      my = sprite(spriteNum)
    end
    
    on mouseUp me
      aTimeout = timeout().new(string(me), 5000, #timeout_callback, me)
    end
    
    on timeout_callback me, aTimeout
      aTimeout.forget()
      my.member = member("Jellyfish_new_1")
    end
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2012 1:35 PM   in reply to Natalie Butler

    Do you have the script set as a behavior and attached to each of your 4 sprites?

     

    Does the debug window tell you anything useful when you choose to open it?

     

    FWIW when I attach the code I posted to a sprite on the stage and click it, there is no script error in D11.5.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2012 4:03 PM   in reply to Natalie Butler

    Do you have a (movie) script or a (movie) handler in your cast libraries anywhere named either 'timeout' or 'new'?

     

    What happens if you issue the following from your message window:

    aTimeout = timeout().new("name", 1000, #callback, 0)
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2012 4:50 PM   in reply to Natalie Butler

    Hi Nathalie,

     

    This is all very strange. Would you like to send me the movie, so that I can see directly what is going on?

     

    You can email it to me at james dot newton at openspark dot com.

     

    Cheers,

     

    James

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2012 5:39 PM   in reply to Natalie Butler

    Is it possible you're updating an older movie that has its scriptExecutionStyle set to 9? What does the following tell you when executed from the message window:

    put the scriptExecutionStyle
    

    If it returns 9, change this by executing

    the scriptExecutionStyle = 10
    

    again from the message window and save your file. Timeouts should now work as expected (test and confirm).

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points