A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: I'm looking for a specific type of audio button

  1. #1
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92

    I'm looking for a specific type of audio button

    Is it possible to make a swf that plays sounds from a url? To be more clear, I mean something like
    Code:
    http://www.site.com/play.swf?=http://www.site.com/sounds/clip1.mp3

    I have a site with a ton of sound files, and it would take forever to add them to individual swf files and put them back on their pages. I'd like the swf to just be a static image that plays the sound when clicked. (preferable with the ability to preload the sound after the click and show a small loading progress bar)

    Thanks,
    Jeff

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    All you need to do is make one movie with a variable referring to _root, something like _root.musicUrl. Then in your html page you add this var with the url:

    PHP Code:
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="300" height="50" id="mp3" align="middle">
    <
    param name="movie" value="mp3.swf?musicUrl=http://www.site.com/sounds/clip1.mp3" />
    <
    param name="quality" value="high" />
    <
    param name="bgcolor" value="#ffffff" />
    <
    embed src="mp3.swf?musicUrl=http://www.site.com/sounds/clip1.mp3" quality="high" bgcolor="#ffffff" width="300" height="50" name="mp3" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
    </
    object
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    Thanks! Now I need to figure out the _root thing you are talking about

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    There is nothing to figure out. This is modified from the help files.

    PHP Code:
    this.createTextField("status_txt"this.getNextHighestDepth(), 0010022);
    // create a new Sound object
    var my_sound:Sound = new Sound();
    // if the sound loads, play it; if not, trace failure loading
    my_sound.onLoad = function(success:Boolean) {
        if (
    success) {
            
    my_sound.start();
            
    status_txt.text "Sound loaded";
        } else {
            
    status_txt.text "Sound failed";
        }
    };
    // load the sound
    my_sound.loadSound(_root.musicUrltrue); 
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    Ohhhh, thanks!
    It plays as soon as the page loads now. I'm just gonna have to try to make it onPress, I think.

  6. #6
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Just put that script in a button
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  7. #7
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    hmm, when I put it on a button, I get errors exporting the swf.

    Code:
    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on handler
          this.createTextField("status_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
    
    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on handler
         var my_sound:Sound = new Sound();
    
    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: Statement must appear within on handler
         my_sound.onLoad = function(success:Boolean) {
    
    **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 15: Statement must appear within on handler
         my_sound.loadSound(_root.musicUrl, true); 
    
    Total ActionScript Errors: 4 	 Reported Errors: 4
    I'll keep trying though. Thanks again!

  8. #8
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Don't do that. Take out the script and put it into the actions on the main timeline. I recommend not to use the on(press) function within buttons at all.

    Name the button my_button and then do this:

    my_button.onRelease = function(){

    script here

    }
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  9. #9
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    heh, I'm sorry, but I'm just not getting it. I'm very new to using flash for things other than simple frame by frame animations.

  10. #10
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    never mind, I got it. thanks!!! I really appreciate the help.

  11. #11
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    ok, one more question. I'd like to make a second button in the same movie (right under the play button) that lets you download the same audio file that the play button uses. Is there a way to link to _root.musicUrl?

    This is what I have so far:
    http://www.aquateencentral.com/v3/audiotest.html

    Thanks!
    Last edited by Atarian; 10-11-2005 at 06:00 PM.

  12. #12
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    Just a little bump for the day crowd

  13. #13
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You link in the same way as in the above script.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  14. #14
    King of the 2600
    Join Date
    Feb 2003
    Posts
    92
    won't that just play the audio when i click the button?

    Thanks!

  15. #15
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    not if you create a download script. Check flash help files for the script.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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