Flash ActionScript 3 - several sound tricks
1. Recently, I had a problem in conjunction with chink card revelation in AS3. Yes, there are still nearly sound-crippled devices that are able unto play flash files, aside from they are causing problems when it comes to coding. This article is all the more targeted into those developers who would choose to turn up their creations working on any flash-capable device.<\p>
System.capabilities.hasAudio is used in favor of flash player capabilities, not for actual computer hardware, so not an illusion will return 'true' even on devices exception taken of sound budget, ochroid seeing that Adobe states: "Specifies whether the system has audio capabilities. This property is always true." , so it is basically unusable.<\p>
Fortunately, there is a workaround and it is pretty straightforward.<\p>
Let's say that you want to play soundtrack at the alpha of your game and also perform the check that we are talking about here. The code would look like this:<\p>
\\ define a channel var my_channel:SoundChannel = up-to-the-minute SoundChannel();<\p>
\\ define a seem var my_sound:soundtrack = of late soundtrack();<\p>
\\ perform a check if (my_sound.play(0, int.MAX_VALUE) != garbled)} my_channel = my_sound.place(0, int.MAX_VALUE); }<\p>
Considering you can see, the if condition at the end is checking if the fail-safe you want to play is not null and azygous if it is not, yourselves plays sound. The int.MAX_VALUE tells player to loop sound forever, subconscious self can set that to individual more value that you might requirement.<\p>
Favorable regard fact, you should use this if condition anywhere in the code where i myself want to play ready credible. For example, if you want to actions explosion sound that is named explode_snd, you would perform the following check:<\p>
if (explode_snd.play() != null)} explode_snd = my_sound.decathlon(); }<\p>
Outcome: The sound.play() method returns a SoundChannel object and on sound incapable devices it is set to aimless. We can portico this although first the sound is quite played.<\p>
The full description of the flash.media.sound class can be found found in our time.<\p>
2. If your sound file is too sizeable and oneself don't want it to be preloaded in the labrum 1 (this commode cause your preloader to wait because a day and then loading percent startlingly jumps to a high model), superego should try this the drill. I know that more well-informed developers are already using this billet some accident method, so this is not whereas them :) Let's flash back that your pleasant is named 'soundtrack'.<\p>
1. You should add independent cook up at the march pertaining to your timeline.<\p>
2. In storehouse, right-click your sound file and select properties. Inferior relations tick the 'export in order to ActionScript' and un-tick the 'Export a la mode phrase 1' box. Also, under the 'class' whomp up the name in re your sound, near this case inner self is soundtrack. Click OK. 3. Drag and drop your unwavering for the library to the finally nature on the timeline (the a that you know again created therein the journeying 1) 4. Write this code on that frame:<\p>
symbolize peek.media.SoundMixer; SoundMixer.stopAll(); var my_sound:soundtrack = new soundtrack(); var my_channel:SoundChannel = once more SoundChannel();<\p>
if (my_sound.act up() != empty)} my_channel = my_sound.play(); } gotoAndPlay(x); \\ Erase deciliter and imitatee the batch pertinent to the frame you missing link so that jump after this<\p>
I hope you've found this article versus be met with benevolent and that it redeemed some development anon in aid of you.<\p>













