A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Audio Trouble

  1. #1
    Junior Member
    Join Date
    Aug 2006
    Posts
    6

    Audio Trouble

    Im having a little trouble with my audio
    I want to be able to put a short sound effect with each of my buttons but i want the audio to start playing as soon as you go over top of it and stop once you leave.. if you could help that would be great

  2. #2
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    Hi Alex---

    Try this:

    PHP Code:

    //sound1 is linkage name of my sound in the library 
    mySound=new Sound();
    mySound.attachSound("sound1");

    myBtn.onRollOver=function()
    {
        
    mySound.start();
    }
    myBtn.onRollOut=function()
    {
        
    mySound.stop();


  3. #3
    Junior Member
    Join Date
    Aug 2006
    Posts
    6
    Quote Originally Posted by FlashSmashed
    Hi Alex---

    Try this:

    PHP Code:

    //sound1 is linkage name of my sound in the library 
    mySound=new Sound();
    mySound.attachSound("sound1");

    myBtn.onRollOver=function()
    {
        
    mySound.start();
    }
    myBtn.onRollOut=function()
    {
        
    mySound.stop();

    Alright... so i have my button created and my audio in the libary... so i just go to my button and add that into the action screen? and change the sound1 to what ever.. lets say toaster sound?

  4. #4
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    pretty much yes, just make sure in the library right click on you sound and click on linkage then tick "export for action script" and give your sund an identifier name, mine for instance was sound1.

  5. #5
    Junior Member
    Join Date
    Aug 2006
    Posts
    6
    I entered what you gave me and had my linkage name for the sound the same and when i went to test it all i got was this:

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 2: Statement must appear within on handler
    mySound=new Sound();

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on handler
    mySound.attachSound("Sound1");

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: Statement must appear within on handler
    myBtn.onRollOver=function()

    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 9: Statement must appear within on handler
    myBtn.onRollOut=function()

    Total ActionScript Errors: 4 Reported Errors:



    So i dont know what i did or didnt do...

  6. #6
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    Hey Alex

    That is because my code should be attached to frame not the button itself, attaching code to the objects in general and button in this instance is not recommended
    (read this document for further information). to fix the problem cut whatever code you have attached to your button and paste it to a frame on the main timeline, don't forget to give your button an instance name. "myBtn" is the instance name of my button in this case. I also recommed to have a read on basic AS and its synatx rulles.

    Good Luck

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center