我正试图在flex中使用声音。我使用urlrequest得到输出,因为我使用的声音文件较少,并且每次调用时都不需要加载。所以我试着把它放在css中并使用它,但我收到一个错误:TypeError: Error #1007: Instantiation attempted on a non-constructor.
以下是我的代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Style>
draw
{
url:"Assets/Sound/Active.mp3";
}
</mx:Style>
<mx:Script>
<![CDATA[
import flash.media.Sound;
import flash.media.SoundTransform;
internal var sound:Sound;
internal var soundVolume:SoundTransform;
public function playSound():void
{
var SoundClass:Class;
try
{
SoundClass = StyleManager.getStyleDeclaration("draw").getStyle("url") as Class;
soundVolume = new SoundTransform(1, 0);
trace("sound : "+sound);
sound = new SoundClass() as Sound;
sound.play(0, 0, soundVolume);
}
catch(E:Error)
{
trace("E "+E);
}
}
]]>
</mx:Script>
<mx:Button click="playSound()" label="Discard"/>
</mx:Application>