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
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
Yes, it is a behavior and is attached to my sprites. I even removed all the other behaviors from the sprites in case they were clashing somehow, but no change.
The debug window doesn't say anything specific, no. Although the value for aTimeout is <Void>, and I'm not sure if it's supposed to be that way or not.
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).
North America
Europe, Middle East and Africa
Asia Pacific