Ask a Question related to Macromedia Director Lingo, Design and Development.
-
JKLea webforumsuser@macromedia.com #1
repeat while...
I'm having difficulty with a repeat loop in some movie controls.
When I press the rewind button and the movieTime reaches 0, it goes back to the menu of movies.
I don't want it to do that, obviously, so I created a repeat loop. It's not working and I suck
at while loops or repeat loops or whatever you want to call them. I want it to keep rewinding
while the movieTime is >= 0 and then when it reaches 0, stop rewinding and play the movie. I have tried several methods and I am now stumped. Since I'm not sure which part of the code is wrong, I'm going to post the whole thing, but keep in mind, everything but the rewind functions like I want.
I only want to fix the rewind function.
Here's the scenario...
I have the following buttons:
skip to beginning -- set the movieTime to 0 and restart the playback
skip to end -- sets the movieTime to sprite(x).duration (go to next track, basically)
rewind --rewinds the clip
fastforward --fastforwards the clip
play --plays the clip
pause --stop playback of the clip, but keeps the original movieTime value
stop --stops the clip and sets the movieTime to 0
I tried using:
repeat while sprite(x).movieTime > 0
if sprite(x).movieTime = 60 then exit repeat --trying to stop it from reaching 0
else set sprite(x).movieTime to sprite(x).movieTime - 300 --rewind 5sec at a time
end repeat
didn't work at all.
So, here's the code with the way I'm leaving it till monday. It's just a last minute attempt at making an if statement work, but it didn't. Any help would be greatly appreciated.
Thanks,
JKLea
global curSprite
on mouseEnter me
curSprite = the spriteNum of me
sprite(curSprite).cursor = 280
end
on mouseWithin me
if the stillDown = true then
case curSprite of
30: -- rewind
if the movieTime of sprite(3) > 60 then
set the volume of sprite(3) to 0
set the movieRate of sprite(3) to 0
if sprite(3).movieTime <= 60 then
set the movieRate of sprite(3) to 1
set the volume of sprite(3) to 255
exit
else
set the movieTime of sprite(3) to sprite(3).movieTime - 300
end if
end if
33: -- fastforward
if the movieTime of sprite(3) < sprite(3).duration then
set the volume of sprite(3) to 0
set the movieRate of sprite(3) to 0
set the movieTime of sprite(3) to sprite(3).movieTime + 300
end if
end case
end if
end
on mouseUp
if sprite(3).movieTime <> sprite(3).duration then
case curSprite of
29: --skip to begining
set the movieTime of sprite(3) to 0
30: --rewind reset
set the movieRate of sprite(3) to 1
31: -- stop
set the movieRate of sprite(3) to 0
set the movieTime of sprite(3) to 0
33: -- fastforward reset
set the movieRate of sprite(3) to 1
34: --skip to end
set the movieTime of sprite(3) to the duration of sprite(3)
35: -- play
set the movieRate of sprite(3) to 1
36: -- pause
set the movieRate of sprite(3) to 0
end case
set the volume of sprite(3) to 255
end if
end
on mouseLeave
sprite(curSprite).cursor = 0
end
JKLea webforumsuser@macromedia.com Guest
-
repeat
I used to play certain games on Shockwave but now when I want to play them it says that I need a media player or a shockwave player. I click to... -
help me with repeat while
Hi! Shouldn't this work; repeat while J < 4 t = member("w3d").newTexture("B",#fromCastMember,member("B")) end repeat -
background-repeat: repeat-x in HTML? Please help!
I want to have a "centered page" look full screen...I have made them using layers and CSS but if I need it to work in most browsers how do I do the... -
Repeat Header??
Hi, Can I repeat the datagrid header every X rows??? Regards Eval -
help with 'repeat'- if I need to(?)
Hi, I am using buddy api to get a list of pc drives: set dl = baDiskList(), then I want to see which of the drives is a cd-rom. If I look at the dl... -
tculley webforumsuser@macromedia.com #2
Re: repeat while...
one of the problems with repeat loops is that director doesn't receive any event messages while it's looping. I would suggest writting a short behavior for each button to simplify your code and to make it more dynamic instead of hard coding your spritenumbers. It is possible to cram all your code into one behavior but for simplicity sake i would start with individual behaviors for each button. Their function will be clearer and better encapsulated.
I usually use the naming convention: beh_bPlay, beh_bPause, beh_bRewind, etc....
I would write a behavior something like the following - using your rewind problem as an example:
--// behavior: beh_bRewind
--// property declarations
property mySprite -- sprite reference
property myMember -- member reference
property myDefaultMember -- static member
property myOverMember -- rollover member
property myDownMember -- down member
property myVideoSprite -- video sprite reference
property pTracking -- boolean flag
property pIncrement -- amount to rewind
--// event handlers
on beginSprite(me)
mySprite = sprite(me.spriteNum)
myMember = mySprite.member
myDefaultMember = myMember
if myDownMember = "" then
myDownMember = myDefaultMember
end if
if myOverMember = "" then
myOVerMember = myDefaultMember
end if
myVideoSprite = sprite(myVideoSprite)
pTracking = FALSE
pIncrement = 5 -- change this value if you want to increase/decrease.
end
on prepareFrame(me)
if pTracking then
-- code you want to execute here
-- something like
if myVideoSprite.movieTime = 0 then
myVideoSprite.movieRate = 1
pTracking = FALSE
end if
if myVideoSprite.movieTime > 0 and myVideoSprite.movieTime <= myVideoSprite.duration
myVideoSprite.movieTime = myVideoSprite.movieTime - pIncrement
end if
end if
end
on mouseEnter(me)
mySprite.cursor = 280
mySprite.member = myOverMember
end
on mouseLeave(me)
mySprite.cursor = -1
mySprite.member = myDefaultMember
end
on mouseUpOutside(me)
mySprite.cursor = -1
mySprite.member = myDefaultMember
end
on mouseDown(me)
pTracking = TRUE
mySprite.member = myDownMember
end
on mouseUp(me)
pTracking = FALSE
mySprite.member = myDefaultMember
end
--// author defined handlers
on getPropertyDescriptionList(me)
pdl = [:]
pdl[#myOverMember] = [#comment:"Over Member:", #format:#bitmap, #default:""]
pdl[#myDownMember] = [#comment:"Down Member:", #format:#bitmap, #default:""]
pdl[#myVideoSprite] = [#comment:"Video Sprite #:", #format:#integer, #default: 1]
return pdl
end
tculley webforumsuser@macromedia.com Guest
-
JKLea webforumsuser@macromedia.com #3
Re: repeat while...
Thanks for the reply.
I acutally got it to work before I saw your post.
Here's what I did...
I put the following into a behavior that's attached to the skipback/forward, rewind, fast forward, play, pause and stop buttons:
global curSprite
on mouseEnter me
curSprite = the spriteNum of me
sprite(curSprite).cursor = 280
end
on mouseWithin me
if the stillDown = true then
case curSprite of
30: -- rewind
if the movieTime of sprite(3) > 120 then
set the volume of sprite(3) to 0
set the movieRate of sprite(3) to 0
set the movieTime of sprite(3) to sprite(3).movieTime - 120
end if
33: -- fastforward
if the movieTime of sprite(3) < sprite(3).duration then
set the volume of sprite(3) to 0
set the movieRate of sprite(3) to 0
set the movieTime of sprite(3) to sprite(3).movieTime + 120
end if
end case
end if
end
on mouseUp
if sprite(3).movieTime <> sprite(3).duration then
case curSprite of
29: --skip to begining
set the movieTime of sprite(3) to 0
30: --rewind reset
set the movieRate of sprite(3) to 1
31: -- stop
set the movieRate of sprite(3) to 0
set the movieTime of sprite(3) to 0
33: -- fastforward reset
set the movieRate of sprite(3) to 1
34: --skip to end
set the movieTime of sprite(3) to the duration of sprite(3)
35: -- play
set the movieRate of sprite(3) to 1
36: -- pause
set the movieRate of sprite(3) to 0
end case
set the volume of sprite(3) to 255
end if
end
on mouseLeave
sprite(curSprite).cursor = 0
end
and then I put this little section into the frame script:
if the movieTime of sprite(3) < sprite(3).duration then
go to the frame
else if the movieTime of sprite(3) >= 120 and the stillDown = true then
go to the frame
else if the movieTime of sprite(3) <= 120 and the stillDown = true then
set the movieRate of sprite(3) to 1
if the volume of sprite(3) <> 255 then
set the volume of sprite(3) to 255
end if
go to the frame
else
go to "Main"
end if
Seems to work fine. I've been testing it and have not run into any trouble, yet.
I don't know enough about this to know if I have any pitfalls coming up because of the coding, but it seems ok for now.
JKLea
JKLea webforumsuser@macromedia.com Guest



Reply With Quote

