0
votes

I a having trouble loading an audio file from the library, I was previously loading the sound files externally like so:

var s1:Sound = new Sound(new URLRequest("Sound/Melody1.mp3"));

However I now need to load them from the library as I have encountered a looping problem with mp3 files.

Below is my attempt, however I am receiving the error: Scene 1, Layer 'Actions', Frame 1, Line 21 1061: Call to a possibly undefined method attachSound through a reference with static type flash.media:Sound.

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

Btn_Melody1.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound1);

var fl_SC1:SoundChannel;

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

function fl_ClickToPlayStopSound1(evt:MouseEvent):void

{

if (fl_ToPlay1)

{
    var s1:Sound = new Sound();
    s1.attachSound("Melody1");
    fl_SC1 = s1.play(0,999);

}
else
{
    fl_SC1.stop();
}
fl_ToPlay1 = ! fl_ToPlay1;

}

I can't see what I am doing wrong, any and all help would be appreciated.

1

1 Answers

1
votes

If you're doing AS3, there is no attachSound method on MovieClip (see doc) (exist in AS2).

In order to use a sound in the library.

1 - add a linkage name to the sound (ex : Sound0);

2 - instanciate your sound :

var sound : Sound = new Sound0();
//do nasty stuff with your sound !