Professional Web Applications Themes

play sound on queue - Macromedia Director Lingo

Hi all I am really stuck on this one. I want to start playing some narrative and then fade in a slide, once the narrative has finished I want to fade out the slide and move on to the next one. I have attached the code I have so far. Please help this is really bugging me. regards Graham -- frame script on prepareFrame me sound(1).play(member("1")) fadeinslide end on exitFrame me if soundbusy(1) then go to the frame else fadeoutslide end if end -- global scripts on fadeooutslide repeat with x=1 to 50 if sprite(60).member.name <> "slide2_1" then sprite(60).blend = ...

  1. #1

    Default play sound on queue

    Hi all

    I am really stuck on this one. I want to start playing some narrative and then fade in a slide, once the narrative has finished I want to fade out the slide and move on to the next one.

    I have attached the code I have so far.

    Please help this is really bugging me.

    regards
    Graham

    -- frame script
    on prepareFrame me
    sound(1).play(member("1"))
    fadeinslide
    end


    on exitFrame me
    if soundbusy(1) then
    go to the frame
    else
    fadeoutslide
    end if
    end

    -- global scripts

    on fadeooutslide
    repeat with x=1 to 50
    if sprite(60).member.name <> "slide2_1" then
    sprite(60).blend = sprite(60).blend -2
    end if

    sprite(61).blend = sprite(61).blend -2
    updatestage

    end repeat
    end

    on fadeinslide
    repeat with x=1 to 50
    if sprite(60).member.name <> "slide2_1" then
    sprite(60).blend = sprite(60).blend +2
    end if

    sprite(61).blend = sprite(61).blend +2
    updatestage

    end repeat
    end



    spydersweb webforumsuser@macromedia.com Guest

  2. #2

    Default Re: play sound on queue

    the code looks reasonable to me, you didn't describe how it's
    malfunctioning.

    A couple of concerns

    naming member with a simlpe number like referenced in
    sound(1).play(member("1")) can be a source of confusion.
    At least tack on a letter so it won't be confused with member number
    references, like (member("s1")


    your fadeooutslide, and fadeinslide loops run at full processing speed,
    probably want to add some internal delay countdown loop delaying the
    iteration rate to between 10 and 60 fades per sec, with perhaps beger
    steps for consistant performance on various systems, better yet make the
    fades increment on exitframe, by setting a status property setting fade
    mode.
    JB Guest

  3. #3

    Default Re: play sound on queue

    Spydersweb,
    The first thing you might want to change is the repeat loop. The following sprite controls don't work well with repeat loop...

    1. Changing the sprite blend
    2. Animating sprites
    3. Changing the foreground or background colors
    4. possibly others that I can't think of as of right now

    Repeat loop are only good for checking varibles and initializing varibles. Heres why. When looping through a loop inside a handler, the stage doesn't get updated until the end of the handler which I see you force the stage to be updated by calling "updateStage". However 'updateStage creates a hidden call procedure to "on prepareFrame" which slows things down not alone slowing things even more when sprites have a "on prepareFrame" inside it's behaviour script.

    also accoriding to the director lingo dictionary I think using isBusy would not work for what you are tring to do. Here is what the dictionary says...

    isBusy, returns TRUE if sound channel channelNum is currently playing or pausing a sound, and FALSE if it hasn't started playing any of its queued sounds or has been stopped.

    So assumming to what I think this means is once the sound channel has been played, it will always return true until the sound channel was told to stop with an event
    "sound(whichChannelNum).stop()". Also assumming from what you posted in this thread, this sound that your are playing sounds like you have it set to loop correct? If so, and from what I understand that the lingo dictionary says, looping the sound will never return isBusy to FALSE once the sound starts playing since your sound is constantly playing.


    Try this...
    Try letting lingo do the math in time for how much to increment the blend of the sprite you are blending.

    [url]http://www.jmckell.com/biasingp.html[/url]

    This url is an example of incrementing the sprite's location form point a to point b. Yes I know, you want to to increment the sprite's blend and not it's locations, but please bare with me. What I am tring show you is how to do incrementation using time. This url will give you better ways to understand incrementation through using the handler "on exitFrame". Using on exitFrame can be very powerfull other then making the play head to hold at it's current frame. Meaning using this syntax "go to the frame". It can also can do those four things that I mention above that repeat loop can't handle too well with. So study this url, download the movie, (you will need to download the movie to see all of the behaviour scripts and movie scripts that are created in this movie), and try to picture that when the sprite is moving, replace that as if that was your sprite that is incrementing it's blend. Then come back to this thread and follow the changes I make


    when you come back follow these intructions

    in your frame script, do the following
    property sp
    property pDuration
    property pMillis

    on beginSprite -- use beginSprite instead of prepareFrame. When looping through a frame, prepareFrame gets called eveytime, and beginSprite only gets called once.

    sp = sprite(60) -- I am using 60 as to what you used in your example.

    -- this syntax down below is so that you don't have to rewrite this script for the next fadein/fadeout
    sp.member = member("my fadein member name")

    pDuration = member("myMemberSound").duration -- where myMemberSound is the name of your sound
    sound(1).play() -- start playing the sound
    pMillis = the milliseconds -- start your timer in milliseconds since the value of sound duration is in millisecnds as well
    end beginSprite

    on exitFrame
    -- this will set the maxium time in the handler "eTimeOnce" so that we know when p will be equaled to 1
    p = eTimeOnce(pDuration)

    -- start off with fade in and calculate fadein
    if p < 1 and sp.member.name = "what ever your fade in member name is" then
    sp.blend = p * pDuration + 0 -- "+ 0" will make the blend start at 0 and add it to p * pDuration

    -- check if fade in is complete by when p = 1
    else if p = 1 and sp.member.name = "what ever your fade in member name is" then
    pMillis = the milliseconds
    sp.member = member("my fadeout member name")

    -- when fadein is complete then calculate fadeout
    else if p < 1 and sp.member.name = "what ever your fade out member name is" then
    sp.blend = 100 - (p * pDuration) -- "100 -" will make the blend start at 100 and then subtract

    --check if fadeout is complete by when p = 1
    else -- this could cause problems. if it does then use else if p = 1 and sp ...... fadeout
    sound(1).stop()
    go to frame "your next marker name"
    end if

    go to the frame
    end exitFrame

    as you can see where I put (go to frame "your next marker name") I would suggest making markers of each fadein/fadeout that you do. Also, instead of reinventing the wheel you can copy the "eTimeOnce" handler from the movie example and paste it this frame script since we don't need to change anything except for changing the varible "millis" to "pMillis" in that handler.


    Roofy webforumsuser@macromedia.com Guest

  4. #4

    Default Re: play sound on queue

    Roofy

    Very many thanks for your reply. If I may ask you another question. I am not so hot on mathematics but presume that the term 'bias' is a mathematical term. Could you give me an explanation of its intent, so I can better understand your demonstration?

    Once again many thanks

    Graham


    spydersweb webforumsuser@macromedia.com Guest

  5. #5

    Default Re: play sound on queue

    You can ignore bias. But just to give you an idea, bias "ease in" will make the sprite to start off to move really fast and then slow down as it gets to point b. Bias "ease out" will make the sprite to move slow and gradually move faster and faster until it reaches point b. Bias "both", will make the sprite move slow and gradually move faster untill it reaches between point a and b and then move slow again. Last, bias "none" of course will have a constant speed from point a to point b. You can really see this better in action if you click on trails. Trails will make the sprite leave it's trackings of each increment and it will show you better how bias works.


    Roofy webforumsuser@macromedia.com Guest

  6. #6

    Default Re: play sound on queue

    Roofy

    thanks for your response, I was wondering if you could give me some further assistance with this one. I sort of have it working but slightly modifying the code. (attached)

    I need the fade in to be a lot quicker than it is and thus have made a direct change to the blend of the sprite rather than referencing the time. Note that using just your original code produced a flicker on the sprite, and I put this down to the fact that (p) was always lower than 1.

    I have the code now so it blends in nice and smoothley but the code only ever breaks out of the initial condition test once. The result is the blend of the sprite reverts to 0 and blends in again continually.

    Therefore I think the, help me out here, the duration of the sound needs to be tested so that when the sounds duration is equivalent to p*pDuration then the next condition should be met?

    purely guess work!!!

    once again many thanks for your help on this.

    Graham
    property sp
    property pDuration
    property pBlend
    property elapsed
    property pMillis

    on beginSprite
    sp=sprite(60)
    sp.member = member("EHElogo")
    -- pBlend = sp.blend
    pDuration = member("1").duration
    sound(1).play()
    pMillis = the milliseconds
    end beginSprite

    on exitFrame

    p = eTimeOnce(pDuration)
    --put integer(p * pDuration / 100)
    put p * pDuration
    -- start off with fade in and calculate fadein
    if p < 1 and sp.member.name = "EHElogo" then

    sp.blend = sp.blend +2 --integer(p * pDuration /100) -- "+ 0" will make the blend start at 0 and add it to p * pDuration
    --updatestage
    -- check if fade in is complete by when p = 1
    else if pDuration = p*pDuration then

    pMillis = the milliseconds
    sp.member = member("EHElogo")
    --sp.blend =100
    --updatestage
    sound(1).stop()
    -- when fadein is complete then calculate fadeout
    else if p < 1 and sp.member.name = "EHElogo" then
    sp.blend = sp.blend -2 -- "100 -" will make the blend start at 100 and then subtract

    --check if fadeout is complete by when p = 1
    else -- this could cause problems. if it does then use else if p = 1 and sp ...... fadeout

    go to frame 100
    end if

    go to the frame
    end exitFrame

    on eTimeOnce(maxMillis)
    elapsed = (the milliseconds) - pMillis
    p = elapsed / float(maxMillis)
    if p > 1 then p = 1
    return p
    end


    spydersweb webforumsuser@macromedia.com Guest

  7. #7

    Default Re: play sound on queue

    Roofy

    Hi again, many thanks for bearing with me on this one. I also ran into a major problem when I produced the standalone projector file. The fade in worked but the sound didn't play. I have know idea what is going on with this and thought that as there was a quicktime movie also on a seperate section of the time line that it was something to do with the sounddevice and so changed it when it came to play the audio, but to no result.

    Any suggestions?

    On reading through the code you sent me I realised that for some reason and a lot of put statements it was only ever meeting the p=1 condition once. This caused a continual looping effect of the image fade in.

    I therefore put the condition around the blend to keep it at 100% once it had been blended to that. The problem I also encountered was, and this was part of the fact that (p) returned to 0 and started incrementing again, that because p=1 only tested true once that the fade out section of the script never came into play. this is why I thought that by testing member.duration against p*pDuration would work.

    as always many thanks.

    Graham


    spydersweb webforumsuser@macromedia.com Guest

  8. #8

    Default Re: play sound on queue

    I have tested this with a sound file of mine which the duration was 915 milliseconds. So why the sprite was blinking was because I forgot to convert pDuration into seconds and then multiply that by 100% blend works from 0% to 100%.

    so when your fading in where the orginal code looked like this...
    sp.blend = p * pDuration + 0

    change it to...
    sp.blend = p * (pDuration / float(1000)) * 100 + 0

    and when fading out when it use to look like this...
    sp.blend = 100 - (p * pDuration)

    change this to...
    sp.blend = 100 - (p * (pDuration / float(1000)) * 100)

    also DON'T FORGET to have 2 differnet members. one for fading in and one for fading out. Yes this can be the same image but you just want to make sure you have 2 different cast member names. I will be back later if you need more explaination. Though I have to now.


    Roofy webforumsuser@macromedia.com Guest

  9. #9

    Default Re: play sound on queue

    I appoligise, as to I missed your sound problem. What type of sound file are you using? Some of them require the shockwave audio Xtra plug-ins



    Roofy webforumsuser@macromedia.com Guest

Similar Threads

  1. play sound on rollover
    By King Evil in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: January 10th, 10:31 PM
  2. I can't get a sound to play
    By djp_phillips in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 1
    Last Post: February 27th, 01:16 AM
  3. How do you play a sound when opening a PDF?
    By Gustavo_Sanchez@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 4
    Last Post: April 27th, 06:48 AM
  4. Play sound from HD
    By WouterVH webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 5
    Last Post: January 26th, 04:36 PM
  5. play sound
    By in forum Macromedia Flash
    Replies: 1
    Last Post: January 12th, 02:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139