Sound not being played - actionscript-3

var sound:Sound = new Sound(new URLRequest("Phone.wav"))
sound.play(0, 20);
Why does sound not play? There are no errors.

Flash doesn't support loading external WAV files with the Sound class, only MP3s. I don't know why it isn't giving any errors but I haven't used the Sound class much myself so it might be normal.
There are three solutions for this. First of all, WAVs are supported if you import them into the library as Sound objects. This is probably the best choice if you're using the Flash IDE.
If you're not using the IDE, you may be able to embed the file instead using Flex's [Embed] tag, if you're compiling it using the Flex SDK.
Otherwise, can either convert your sound to an MP3 file and load it as usual:
var sound:Sound = new Sound(new URLRequest("Phone.mp3"));
sound.play(0, 20);
Or, if you prefer to use a WAV, you can use the as3wavsound library. Here's a tutorial outlining how to use it.
Hope that helps!

You need to use a SoundChannel try this.
var soundChann:SoundChannel;
var sound:Sound = new Sound(new URLRequest("Phone.wav"))
soundChann = sound.play();

Related

How make with AS3 downloading MP3 files in the background mode and plays it?

I need help with AS3 make downloading MP3 files in the background mode. Man goes to my site and it will automatically load MP3 file on his computer and plays it. I read these examples here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html but do not know how to do it? Prompt what code and how to use it properly?
You can directly load a Sound object with an URLRequest instead of using a separate Loader or URLLoader. A code could look like this:
// this code should reside in a function somewhere
var request:URLRequest = new URLRequest("http://your.site.com/your.mp3");
var sound:Sound = new Sound(request;
sound.addEventListener(Event.COMPLETE, completeHandler);
// this function should be at top level anyway
private function completeHandler(event:Event):void
{
var loadedMP3:Sound = Sound(event.target);
if (loadedMP3) loadedMP3.play();
}
Extra error handling is up to you.

Shoutcast aacplus streaming with As3

i want a flash player for shoutcast servers. if shoutcast's content type is mpeg, codes is working. But if shoutcast's content type is aacp, codes not working.
Codes;
var channel:SoundChannel;
var sound:Sound = new Sound();
sound.load(new URLRequest("http://yonradyo.radyolarburada.com:8020/;"));
channel = sound.play();
What should I do? Thanks.
The Project Thunder Snow (https://code.google.com/p/project-thunder-snow/) is not so fresh, but still working solution for playing aac/aacp streams on PC (but not on mobile platform).
The page https://code.google.com/p/project-thunder-snow/wiki/NBaccPlayer contains a code example simple enough.

easiest way to add a swf animation in a flash builder project

I have a very simple flash aimation (frame based) thatI just have to run once. What is the quickest and easiest way to embed this into flash builder 4.6.
I have tried about 5 or 6 different ways but cannot seem to get it, mainly due to type mismatch and even with casting it di not work.
I tied the embed metatab but should I be using the loader() class?
Try this:
[Embed(source="movie.swf", mimeType="application/octet-stream")]
const movieClass:Class;
var loader:Loader = new Loader();
loader.loadBytes(new movieClass() as ByteArray);
addChild(loader);

How do I include flashvars in AS3?

I am brand new to AS3 and I am trying to move all of the data from an html file, into a swf.
The old html file contained this coding:
<EMBED src="https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf" WIDTH="640" HEIGHT="528" FlashVars="_tunervar_shost=www.pandora.com">
So far from what I have learned I can use the loader, to substitute for the src. So in my swf, I have
var myLoader:Loader = new Loader();
addChild(myLoader);
var url:URLRequest = new URLRequest("https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf");
myLoader.load(url);
What I can't figure out though, is how to change the FlashVars from html into AS3. I have done a bit of research and from what it sounds like, I have to use something called root. I am completely lost on how to use this, and I am not even sure if this is the correct way to script it. Can someone help explain this to me?
One other problem I am having, is for some reason, the swf I am loading is blurry. Is there any way to fix this?
Try appending them to the asset that you're loading:
var url:URLRequest = new URLRequest("https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf?_tunervar_shost=www.pandora.com");

Audio of a specific video swf doesn't stop when I load another URLRequest

I am trying to stop the audio of the video swf and I can't get it to stop. Here is my code for loading the file:
var myLoader:Loader= new Loader();
myLoader.x=420;
myLoader.y=200;
// boolean variable set for use below in our function
var screenCheck:Boolean = false;
//These three linces keep stafe elements the same size, so they don't distort
var swfStage:Stage = this.stage;
video_btn.addEventListener(MouseEvent.CLICK,contentvideo);
function contentvideo (event:MouseEvent):void{
myLoader.load(new URLRequest("prevideo.swf"));
addChild(myLoader);
movie_btn.stop();
movie_btn.visible=false;
}
Now I have other functions that load different URLRequest and when they are loading, the audio keeps playing. Do I have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing.
I'm not familiar with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that
addChild(myLoader);
has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?
A shot in the dark I know but I thought I'd offer the possibility anyway.