views:

38

answers:

1

In Flash 10/AS3, I added some sound and it seems to be working alright, but I think I'm doing it wrong. I imported the sound into the library, but I believe that it's reloading it from the folder with the swf/sound. I'm loading them like so:

var request1:URLRequest = new URLRequest("CLICK8C.mp3");
clickSound = new Sound();
clickSound.addEventListener(Event.COMPLETE, completeHandler);
clickSound.load(request1);

Is there a way to get it to just load it from the library?

A: 

You need to make the sound in the library available to actionscript. After that, you can implement the sound object like any other class.

To make a library object available for actionscript, left click the item in the library and select 'Linkage'. Check the box next to 'Export for ActionScript'. You'll need to then give the object a class name and since you are dealing with a sound, make sure the base class is a Sound object.

Let's say you named your sound class "MySound", you can now access this object via actionscript like this (incorporating your code from the question):

var mysound:MySound = new MySound(); 
mysound.addEventListener(Event.COMPLETE, completeHandler); 
mysound.play();

note: if you want to further control the sound (stop, rew, etc), you'll need to create a SoundChannel object. (see documentation below)

Adobe Sound Object Documentation

turkeyburger
Thanks, I thought I might have forgotten something like that. I already have the SoundChannel and stuff. :)
Ullallulloo