Posted By

ericfickes on 08/12/09


Tagged

class sound funny of AIR Flex mxcoreSoundAsset flashmedia soundboard kind SoundChannel


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

cnsaturn


Sourcecode for ifartair.com AIR / Flex soundboard


 / Published in: MXML
 

URL: http://www.ifartair.com

Here is the MXML source code for a simple FLEX based soundboard. You can download this Adobe AIR application at http://www.ifartair.com/

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" borderColor="#010101" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#000000, #020202]" width="150" height="150" horizontalAlign="center" verticalAlign="middle">
  3.  
  4. <mx:Script>
  5. <![CDATA[
  6. import mx.core.SoundAsset;
  7. import flash.media.*;
  8.  
  9. [Embed(source="../sounds/fart1.mp3")]
  10. [Bindable]
  11. public var fart1:Class;
  12.  
  13. [Embed(source="../sounds/fart2.mp3")]
  14. [Bindable]
  15. public var fart2:Class;
  16.  
  17. [Embed(source="../sounds/fart3.mp3")]
  18. [Bindable]
  19. public var fart3:Class;
  20.  
  21. [Embed(source="../sounds/fart4.mp3")]
  22. [Bindable]
  23. public var fart4:Class;
  24.  
  25. [Embed(source="../sounds/fart5.mp3")]
  26. [Bindable]
  27. public var fart5:Class;
  28.  
  29. public var myFart1:SoundAsset = new fart1() as SoundAsset;
  30. public var myFart2:SoundAsset = new fart2() as SoundAsset;
  31. public var myFart3:SoundAsset = new fart3() as SoundAsset;
  32. public var myFart4:SoundAsset = new fart4() as SoundAsset;
  33. public var myFart5:SoundAsset = new fart5() as SoundAsset;
  34.  
  35. public var channel:SoundChannel;
  36.  
  37. //index of currently playing sound
  38. private var idx:int = 0;
  39. //max number of embedded sound files
  40. private var iSoundCt:int = 4; //HACK : use zero indexing for access in fart()
  41.  
  42. //sounds collection
  43. private var aSounds:Array = new Array( myFart1, myFart2, myFart3, myFart4, myFart5 );
  44.  
  45. //temp ref to sound
  46. private var tmpSound:SoundAsset;
  47.  
  48. //play sound
  49. public function fart():void
  50. {
  51. // Make sure we don't get multiple songs playing at the same time
  52. stopSound();
  53.  
  54. //get reference to sound
  55. tmpSound = aSounds[ idx ];
  56.  
  57. // Play the song on the channel
  58. channel = tmpSound.play();
  59.  
  60. //increment or reset index
  61. if( idx == iSoundCt )
  62. {
  63. idx = 0;
  64. }
  65. else
  66. {
  67. idx++;
  68. }
  69. }
  70.  
  71. public function stopSound():void
  72. {
  73. // Stop the channel, but only if it exists
  74. if ( channel != null ) channel.stop();
  75.  
  76. tmpSound = null;
  77. }
  78. ]]>
  79. </mx:Script>
  80.  
  81. <mx:Image id="img_air" source="@Embed('../images/air_flex_small.jpg')" autoLoad="true" scaleContent="true" click="fart()" mouseOver="fart()" />
  82.  
  83. </mx:WindowedApplication>

Report this snippet  

You need to login to post a comment.