Embedding mp3 sounds in flex css stylesheets

Here is a simple method of how to embed an mp3 file into css and play it in an application.

There is not alot of info out there on how to do this and I found out basically by trial and error so I hope this may be of use to some of you. Also... I'm not sure if this is the best practise way of doing this, there may be another way that is simpler or better... please let me know if you find something

NOTE: In the example, for simplicity sake, I have put the style declaration into the actual mxml application. This can also be done using an external css style sheet if you like.

 






private function playEmbeddedSound():void{
var soundCSSClassDec:CSSStyleDeclaration
= StyleManager.getStyleDeclaration("MySound");
var MySoundClass:Class = (soundCSSClassDec.getStyle("url")) as Class;
var myEmbeddedSound:Sound = new MySoundClass() as Sound;
myEmbeddedSound.play();

}

]]>



MySound{
url: Embed(source='assets/alarm.mp3');
}




Comments
Add New
Powered by !JoomlaComment 3.26

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 

Help my beer fund

RocketTheme Joomla Templates