Adding music-Please Help!

New Here ,
Aug 13, 2020 Aug 13, 2020

Copy link to clipboard

Copied

Let me preface this...I am a student learning Animate. I have knowledge of Photoshop and Illustrator previous to going to school. (Just want you to know what my limitations might be).  

 

I am making a short "game". I am using scenes. I want to add a music button to each level that plays the music automatically but has a start/stop feature. I was trying to use this code - 

 

/* Click to Play/Stop Sound
Clicking on the symbol instance plays the specified sound.
Clicking on the symbol instance a second time stops the sound.

Instructions:
1. Replace "http://www.helpexamples.com/flash/sound/song1.mp3" below with the desired URL address of your sound file. Keep the quotation marks ("").
*/

instance_name_here.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);

var fl_SC:SoundChannel;

//This variable keeps track of whether you want to play or stop the sound
var fl_ToPlay:Boolean = true;

function fl_ClickToPlayStopSound(evt:MouseEvent):void
{
                if(fl_ToPlay)
                {
                                var s:Sound = new Sound(new URLRequest("http://www.helpexamples.com/flash/sound/song1.mp3"));
                                fl_SC = s.play();
                }
                else
                {
                                fl_SC.stop();
                }
                fl_ToPlay = !fl_ToPlay;
}

 I found the song that I want but it was a download from a free site. How do I convert that to a url? Any ideas? Thanks in advance for any help.

Tracey

TOPICS
ActionScript, Code, How to, Other

Views

42

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 14, 2020 Aug 14, 2020

Copy link to clipboard

Copied

LATEST

you need to download the sound first and then (when download is complete), play it (but that might cause a cross-domain security issue).

 

so you should download it and then either play it locally, or import it to your library and play it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines