Function to fade audio smoothly from one level to another in AS2

Greetings all.
I'm a newcomer to Actionscript programming and trying to modify a Flash site template downloaded from TemplateMonster.com (which is an AS2 template).  I've almost succeeded at what I need to do but have run into a couple of brick walls.  One is that I've added a video player to the site and need to make the background music track smoothly fade out when the video starts and fade back in when it ends (or is stopped).  I set up a listener object for the video player that works.  It's the smooth fade of audio levels that doesn't.
I found an excellent thread from last year (http://forums.adobe.com/message/3236495) in which kglad address the issue of fading audio from one level to another.  Since TemplateMonster's templates set up a master movie clip and then load pages to play within it, and I need to call the function from within the pages, I tried setting it up as a global function.
So when the overall site initializes, I have this:
this.createEmptyMovieClip("mcMusictrackHolder", this.getNextHighestDepth());
var sndAudio:Sound = new Sound(mcMusictrackHolder);
var nMaxMusicVolume:Number = new Number(mcMusictrackHolder);
nMaxMusicVolume = 30;
sndAudio.attachSound("MusicTrack");
sndAudio.setVolume(nMaxMusicVolume);
sndAudio.start(0,9999);
// Here is kglad's function converted to a global function
_global.fadeSoundF = function(mc:MovieClip,s:Sound,vol:Number,sec:Number):Void
     trace("Getting here with sound at " + s.getVolume());
     clearInterval(mc.fadeI);
     var volumeInc:Number = vol-s.getVolume()/(10*sec);
     mc.fadeI=setInterval(fadeF,100,mc,s,volumeInc,vol);
     trace("Leaving with sound at " + s.getVolume());
function fadeF(mc:MovieClip,s:Sound,inc:Number,endVol:Number):Void
     s.setVolume(s.getVolume()+inc);
     if(Math.abs(s.getVolume-endVol)<inc)
          clearInterval(mc.fadeI);
Then within the page that contains the video player (a child of the above), I have this:
var listenerObject:Object = new Object();
var sCurrentState:String;
listenerObject.stateChange = function(eventObject:Object):Void
sCurrentState = my_FLVPlybk.state;
if (sCurrentState == "playing")
  fadeSoundF(_root.mcMusictrackHolder,_root.sndAudio,0,1);
else
  fadeSoundF(_root.mcMusictrackHolder,_root.sndAudio,_root.nMaxMusicVolume,1);
my_FLVPlybk.addEventListener("stateChange", listenerObject);
The listener object is working fine - so if instead of calling fadeSoundF I simply do _root.sndAudio.setvolume(0) to mute and _root.sndAudio.setvolume(30) to restore it works fine except that the volume changes abruptly instead of ramping.
But obviously there's a problem with my effort to convert kglad's function to global and use it that way, because the trace statements tell me the audio is getting set to random levels.  It smoothly ramps all right - but tries to get to -472 or +8212 or other insane numbers.
Any help with where I'm going wrong would be deeply appreciated.  Keep in mind that although I have some long-ago programming experience in other languages, this environment is completely alien to me and you can feel free to assume I'm completely ignorant.  What I've managed to piece together is largely pulled from online research, which is why there's probably an obvious glaring error in there.  Feel free to provide a response that assumes I know nothing.
Best,
Pete

I added a few more traces.  Here's the new main page:
this.createEmptyMovieClip("mcMusictrackHolder", this.getNextHighestDepth());
var sndAudio:Sound = new Sound(mcMusictrackHolder);
var nMaxMusicVolume:Number = 30;
sndAudio.attachSound("MusicTrack");
sndAudio.setVolume(nMaxMusicVolume);
sndAudio.start(0,99999);
_global.fadeSoundF = function(mc:MovieClip,s:Sound,vol:Number,sec:Number):Void
          trace("Getting here with level at " + sndAudio.getVolume());
          trace("asking to set it to " + vol + " in " + sec + " second(s).");
          clearInterval(mc.fadeI);
          var volumeInc:Number = vol-s.getVolume()/(10*sec);
          mc.fadeI=setInterval(fadeF,100,mc,s,volumeInc,vol);
          trace("Leaving with sound at " + sndAudio.getVolume());
          trace(" ");
function fadeF(mc:MovieClip,s:Sound,inc:Number,endVol:Number):Void
          s.setVolume(s.getVolume()+inc);
          if(Math.abs(s.getVolume-endVol)<inc)
                    clearInterval(mc.fadeI);
Here's sample trace output:
Getting here with level at 30                  <---- this is on first visiting the page where the listener object initializes and asks it to ramp the audio from its
asking to set it to 30 in 1 second(s).             current level to the same level (probably because the video is buffering or rewinding and that counts as a state change).
Leaving with sound at 30
Getting here with level at 111                <---- this is a second triggering of the function (probably because the video is STOPPED and that counts as a
asking to set it to 30 in 1 second(s).            state change after buffering).  As of yet the video hasn't been asked to play.
Leaving with sound at 111
Getting here with level at 3765               <---- This is what happens when the video is asked to play; since it is asking to leave the level at 30 I'm guessing it is buffering
asking to set it to 30 in 1 second(s).              again but not playing yet, which is why it's still being asked to set the background to 30 instead of 0.
Leaving with sound at 3765
Getting here with level at 3765                <---- NOW the video is actually playing, so it asks to set the background audio to 0.
asking to set it to 0 in 1 second(s).
Leaving with sound at 3765
Getting here with level at -41740             <---- ... and I hit STOP, which generates a request to bring the background audio back to 30.
asking to set it to 30 in 1 second(s).
Leaving with sound at -41740
I should probably replace the if/else on the video player page with a switch/case so the function ONLY gets called when playback actually stops and starts, and doesn't get triggered for every state change.  But I think I still have an error in here someplace...
Many thanks to kglad for your help!
Pete

Similar Messages

  • Converting  audio file from one format to another format

    Hi Friends,
    Is it possible to convert the audio file from one format to another format(*.mp3 to *.wav file and vice versa)?
    If so, please guide me on the same.
    Thanks in advance,
    Kavitha Anbazhagan

    It's been covered here already, but take a look here:
    Converting CDs to iTunes Audiobooks
    Just read the parts after the section on importing from CD.
    Regards.
    Message was edited by: Dave Sawyer

  • How do I transfer audio books from one computer to another via Iphone?

    I purchase 2 audiobooks on an iphone 4 and I synced them with a different computer and put them on the computer. I no longer have the phone to put on the main computer. How do i transfer songs from one computer to another?

    You can try using DROPBOX.
    Get them on both computers and drag and drop.
    It's free depending on how much you are transferring.

  • Need to move an audio track from one mkv to another one

    Hi,
    I'm trying to recover some files that were deleted by a customer.
    We have in hand:
    1) High Resolution MKV ( H264 + AC3 ) of a final video product (a couple of header videos about 1:44s have been added to the head).  ~ 1h10m
    2) Low Resolution MKV  ( MP4  + MP3 ) of a final vidoe product but with a different audio track.
    Now it was easy enough to extract all of these into their individual components. 
    So What I really have is:
    1) H.264 1920x1080 video
    2) AC3 of final audio track
    3) Commentary track
    Now what the customer wants is to combine these into a single video package (mkv) that has a "director's commentary" track.
    I pulled the components into Premier CC but for some reason it can't seem to be able to keep up with the 1920 source video (??? shows a few frames, stops for 30 seconds [audio continues] then another couple of frames of video, etc.. ) so that I can drop in the commentary audio in the right place.
    Now this machine is no slough, it's a i7-4820k @ 3.70 GHz, 32GB RAM, SSD drives, win 8.1 64-bit.   I have done a ton of DSLR videos but never a .264 file.   
    1) Any idea on why the video isn't keeping up in "Program"? At Full, 1/4 or 1/8?
    2) How do I create the final output with multiple distinct tracks?  [ I've never done that before ]
    Thanks.

    How do I create the final output with multiple distinct tracks?
    Adobe Suite is the wrong tool for doing this job. You need to mux them in e.g. ffmpeg, using -map option and -itsoffset if audio stream from your low res MKV has different duration.

  • How to pass the value from one level to another level

    Example :
    we have secnario for leave process
    initiall the user enters the name in first action the personal number should pick from first action to background RFC CO to pick the Payroll admin from R/3
    i designed the first data input form.... i want to pick the personal number and pass that one to next action in background mode.
    thanks in advance
    sukumar

    Hi,
    If you want to execute the step in background then you can use the callable object of type "Background Execution" or if you want to do any user interaction on that step then you can go for web dynpro callable object. Here is the link for Background Execution callable object.
    http://help.sap.com/saphelp_nw70/helpdata/en/9a/e8934258a5ca6ae10000000a155106/frameset.htm
    Here is also link for Web Dynpro Callable Object
    http://help.sap.com/saphelp_nw70/helpdata/en/de/8976417f2d5558e10000000a1550b0/frameset.htm
    If you have any conficution please let me know.
    Thanks
    Chandan

  • How can I copy a track from one session to another?

    I want to copy an entire track (strip setting and audio/midi) from one session to another. The only option I can seem to find is to bounce or export as audio.
    Is there any way to do this besides copy/paste the strip setting, copy/paste the software instrument, copy/paste the midi?

    Why don't you save the channel strip (including the Software instrument) as a preset and insert it in the new session? Doesn't affect Volume and panning though unless it is automated. Then you could copy+paste the Automation. Audio and Midi files have to be copied+pasted.

  • Edit Text from one screen to another screen

    Hi Experts,
           Here I am having two doubts in doing functionality on SMP 2.3,The below mentioned are the doubts,
                       1. In SMP 2.3 Version,When i am doing Hybrid App Designer in that  Edit Text functionality to pass the values from one screen to another screen,we want to type any text or digits in edit text keypad options is not opening in that field.If any one knows to handle that issue please let me know experts.
                       2.  In SMP 2.3 Version,When i am doing Hybrid App Designer we are taking some labels or buttons or edit box etc....,first time i am generating the hybrid app it is displaying in the mobile device what ever i give in that screen.Afterwards when i am updating second time in that screen with extra functionality labels or buttons or edit box etc...,and generating hybrid app,these time it is not displaying in mobile device which i gave not updating.If any one knows to handle that issue please let me know experts.
         For these both isssues if anybody gets solutions to handle these data please let me know and if links are there please provide it .
    Thanks & Regards,
      Lokesh Reddy G,
      9700414490.

    Hi Lokesh,
    Regarding your queries:
    1. What kind of device/simulator and OS you are testing your app? What is its version?
    Can you share the snapshots as well?
    2. What extra functionality you have added 2nd time? When you generating hybrid app 2nd time is it uploading in HWC container successfully?
    Meanwhile you can check this blog
    A workflow Application to Release A Purchase Order...
    Rgrds,
    Jitendra

  • Editing audio from one project to another

    I'm trying to build a DVD project of different musical performances in Final Cut Pro X. The Mac I'm working with crashes every 30 minutes regardless of what I'm doing so, instead of building a monstrous timeline with two hours worth of performances on it (which will never save given the crash issues), I'm trying to build it by each song (4-6 minutes each).
    The format is: opening billboard (with performer and song listed) --> fade into performance --> performance --> fade out of performance. If I were fading the audio out after each song, it would be simple but I'm trying to keep some of the audience track going under the next billboard so it blends better. I can't seem to cut the audio at the end of the fade out and apply it to the next song without continuing to build onto the same timeline which, due to the crash issues, doesn't help me.
    Is there an audio work around that I'm missing? All I want to do is fade the audio a little past the fade effect, copy it and apply it to the beginning of the next song. Anyone?

    Just ran into the same problem myself... while I get you CAN export the audio, then import it and use anyway you like I don't think that is the point of the original poster's question.
    The voice-over clip has unique properties and as such I (and it looks like other users) would like to be able to "copy & paste" a voice-over clip from one project to another. Alternatively if I could drag and drop the voice-over clip into my Event that would be great too. Doesn't seem like an unreasonable request. Right now the famed Apple ease-of-use is missing for those of us who have recorded voice over elements we want to use in more than one project.
    Had I known iMove would not allow sharing of voice over clips within iMovie I would have recorded my voice-over clips in another application and imported them all as audio-clips. Which certainly defeats the point of the inclusion of voice-over in iMovie.
    Any solutions that work within the app without an export/import required?

  • Using an audio from one video to another

    I am trying to make a documentary type film and I want to use an audio segment from one video to overlap another video's audio while using the second video just for the video. Here is an example of it.
    http://www.youtube.com/watch?v=9u7dJXDhOjc
    Im trying to acheive what they did for the first 15 seconds of this clip. I use movie 08.

    This is easy in iMovie 09.
    Here is [how to do it in iMovie 08|http://imovie08.blogspot.com/2007/08/how-to-extract-audio-from-clip.html]

  • How do I reorganize my photos on iPad 2?  I need to move (not copy) photos from one album to another.  When I use the copy function to another album, and then try to delete an image from the original album, the system wants to delete the photos from all a

    How do I reorganize my photos on iPad 2?  I need to move (not copy) photos from one album to another.  When I use the copy function to another album, and then try to delete an image from the original album, the system wants to delete the photos from all albums.  Please help.

    You can't do it directly on the iPad - the new album functionality basically only allows you to copy photos into those new albums, you can't move them. The way that I think of it as working is that you are just creating pointers to the photos in those new albums, so if you then delete the original photo on the iPad you therefore automatically delete all the pointers to it.
    If you want to re-organise your albums then you will need to do it on your computer and then sync those albums over to the iPad

  • ABAP Function Module Example to move data from one Cube into Another

    Hi experts,
    Can any please help out in this ..?
    A Simple ABAP Function Module Example to move data from one Cube into Another Cube
    (How do i send the data from one client to another client using Function moduel).
    Thanks
    -Upen.
    Moderator message: too vague, help not possible, please describe problems in all technical detail when posting again, BI related? ("cube"), also search for information before asking.
    Edited by: Thomas Zloch on Oct 29, 2010 1:19 PM

    This is the start routine to duplicate records in two currencies.
    DATA: datew   TYPE /bi0/oidateto,
          datew2  TYPE rsgeneral-chavl,
          fweek   TYPE rsgeneral-chavl,
          prodhier TYPE /bi0/oiprod_hier,
          market  TYPE /bic/oima_seg,
          segment TYPE /bic/oizsegment.
    DATA: BEGIN OF S_DATA_PACK OCCURS 0.
            INCLUDE STRUCTURE /BIC/CS8ZSDREV.
    DATA: END OF S_DATA_PACK.
    S_DATA_PACK[] = DATA_PACKAGE[].
      REFRESH DATA_PACKAGE.
      LOOP AT S_DATA_PACK.
        move-corresponding s_data_pack to DATA_PACKAGE.
        if DATA_PACKAGE-loc_currcy = 'EUR'.
          DATA_PACKAGE-netval_inv = DATA_PACKAGE-/bic/zsdvalgrc.
          DATA_PACKAGE-CURRENCY = 'USD'.
          APPEND DATA_PACKAGE.
          DATA_PACKAGE-netval_inv = DATA_PACKAGE-/bic/zsdvalloc.
          DATA_PACKAGE-CURRENCY = 'EUR'.
          APPEND DATA_PACKAGE.
        else.
          DATA_PACKAGE-netval_inv = DATA_PACKAGE-/bic/zsdvalgrc.
          DATA_PACKAGE-CURRENCY = 'USD'.
          APPEND DATA_PACKAGE.
        endif.
      ENDLOOP.
    This is to load Quantity field
    RESULT = COMM_STRUCTURE-BILL_QTY.
    This is to load Value field
    RESULT = COMM_STRUCTURE-NETVAL_INV.
    UNIT = COMM_STRUCTURE-currency.

  • Since I migrated my files from one Mac to another and am now running Yosemite, Photoshop Elements 9 (adequate for what I do) is not showing the previous functionality on some of the tools. I have uninstalled/reinstalled twice to no avail.

    Since I migrated my files from one Mac to another and am now running Yosemite, Photoshop Elements 9 (adequate for what I do) is not showing the previous functionality on some of the tools. I have uninstalled/reinstalled twice to no avail.  Is there a fix? Also, when I tried to update, it comes up with this error.

    I have a similar problem. I found out that my macbook air created a new USER with my former's computer user name. You can check that by going into System Preferences -> User & Groups, and see if a "Other user" has been created. You have to login under this new USER to find your transferred contacts in the address book.
    My problem is that I do not know how to merge the 2 USER logins or transfer the data from the new USER created into the existing one.

  • Functional module to Copy measurement points from one equipment to another

    HI,
    Please give some body function module to Copy measurement points from one equipment to another which is not assign to functional location.

    To Copy Measuring Points from one equipment to another , Go to transaction IE10 and copy all the relevant data that need to be copied Check the measuring point check box, it would copy the characteristic for measuring point to the newly created equipment and would create a system generated number for the measuring point. Both the measuring points would have the same characteristics and if they are attached to each other in a hierarchy then the measurement document readings could also be transferred from one measuring point to another.. You could use the following Function Module "EQUIPMENT_COPY" to copy the measuring point from one equipment to another if equipment has already been created.
    Regards...
    Edited by: Usman Kahoot on Jun 9, 2010 2:37 PM

  • Unable to switch from one level tabs to two level tabs.

    I created my application using one level tabs. When I created parent tabs they didn't show up. I have changed the Page property to Two Level Tabs in the Default Templates by Component section of the Define Theme page. But the 2 level tabs just not show. After some trials even the 1 level tabs dissapeared. I can't see any tab now.
    Is there any method to switch safely from one level tabs to two level tabs and have them show properly?
    Francisco

    I developed my own solution after several days of
    working on the issue, and it is kind of complex. I
    have a 12 page word document with images explaining
    the process, so I cannot post it here. I responded to a thread on this forum several weeks back about this topic. I guarantee that the posts in total in that thread could never fill a 12 page document. It's not that complicated.
    You can find it here:
    Re: Can someone explain the diference between the tabs and the tab sets?
    The main problem when switching from one-level tabs to two-level tabs is the "psuedo-parent-tab" that gets created as a container reference for the standard tabs. Once you get past that - and change the default template for your application you're well on your way.
    Earl

  • How can we transfer stock from one vendor to another vendor?

    Dear Gurus,
    How can we transfer stock from one vendor to another vendor?
    pls tell the steps to follow..
    Thanks..

    This is the Normal Third Party Sub Contracting
    Follow these steps
    If components to be provided to a vendor are supplied not by your company but by a third-party, you can order the components from the third-party and specify the subcontractor in the purchase order as the delivery address. At goods receipt the components are posted directly to the stock of the material provided to vendor.
    Entering a Purchase Order for Components
    To order components for a subcontract order from a vendor and have them delivered direct to the subcontractor, enter a standard purchase order with a different delivery address:
    From the Purchasing menu, choose Purchase order ® Create ® Vendor known.
    Maintain the data on the initial screen. Make sure you enter the vendor of the components and the plant concerned.
    Enter the items.
    Then choose Item ® More functions ® Delivery address.
    A dialog box appears in which you enter the delivery address.
    In the field Vendor enter the number of the subcontractor and select the SC vendor box.
    Selecting the box causes the components at goods receipt to be posted directly to the stock of the material provided to vendor when the goods receipt is posted.
    Save the purchase order.
    Posting the Goods Receipt of the Components
    If the subcontractor lets you know that the components have arrived, you can enter the goods receipt for the purchase order. The components are posted directly to the stock of the material provided to vendor.
    Stock Update
    A goods receipt posting has the following results in the system:
    the stock of material provided to vendor at plant level is increased. The stock of material provided to vendor is not managed at storage location level, since the stock is no longer stored at your company.
    Valuated stock at plant level increases.
    Documents
    An accounting document is created for the material document.
    After this normal subcontracting order for finished product.

Maybe you are looking for

  • MSI 845PE MAX2-FIR...6 USB Ports?

    Okay, so I recently installed my MSI mobo. everything went exceptionally well. No major issues at all...except...  Well, here goes... The manual states that this motherboard has 6 USB 2.0 compatability...2 Rear, and 4 Front.  Okay, obviously the 2 re

  • How to use live type in motion 4

    how to use live type in motion 4

  • Is this  Bug?

    double click the "amount" In "open items list",  B1 prompt a error message, then click "OK" B1 is exit! Who have same problem?

  • Bluetooth mobile peers can't send files to Mac

    Bluetooth mobile peers can't send files to Mac This is about os x 10.9.5 on Mac 2013 late. For the test additionally two mobile devices are used, one is a mobile phone with some old version of Symbian, the other one is an Android device approx 1 year

  • DocX files from Word 2007

    These are a horrible mess when I import them into Frame 8. Half the file is formatted wit Courier font. I have the Word 2003 compatibility pack installed and saving the file down to Word 2003 format doesn't help at all--still a frightful mess. I am u