0

我正在尝试在 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>
4

1 回答 1

1
draw {
   url:Embed(source="Assets/Sound/Active.mp3");
}

参考这个

于 2013-09-26T08:25:54.710 回答