问题
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?
回答1:
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
回答2:
The top answer has managed to get some of the code incorrect.
Here is a more simplistic version.
var mysound:Sound = new (mySound);
mysound.play();
}
Just change your internal sound file class name to mySound.
来源:https://stackoverflow.com/questions/2702140/how-to-play-sound-from-library-in-as3