簡體   English   中英

在Flex中將聲音嵌入CSS

[英]Embed Sound in CSS in flex

我正在嘗試在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>
draw {
   url:Embed(source="Assets/Sound/Active.mp3");
}

推薦這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM