Sounds Don't Always Load AS3 - actionscript-3

I do not know why, but whenever I try to load a sound into my game, it sometimes works and sometimes doesn't.
When it works, the only output is some newgrounds api.
But sometimes, this happens:
Error opening URL 'http://www.newgrounds.com/audio/download/700566'
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at rotationgame_fla::MainTimeline/frame1()
at flash.display::MovieClip/gotoAndStop()
at com.newgrounds.components::FlashAdBase/set showBorder()
at com.newgrounds.components::APIConnector/__setProp_ad_APIConnector_AD_0()
at com.newgrounds.components::APIConnector/__setProp_handler()
I dont know why, but here is my code for all the audio
Frame 1
var bkgmusic:Sound= new Sound();
bkgmusic.load(new URLRequest("http://www.newgrounds.com/audio/download/700566"));
var igmusic:Sound=new Sound();
igmusic.load(new URLRequest("http://www.newgrounds.com/audio/download/651218"));
Frame 2
import flash.media.Sound;
import flash.net.URLRequest;
var channel:SoundChannel = new SoundChannel();
channel=bkgmusic.play();
Frame 3
channel.stop();
channel=igmusic.play();
Frame 4
channel=bkgmusic.play();
I can't give you the code for the API connector (for newgrounds), but if you agree to their API terms of service, you can see for yourself.
The only thing it seems to affect is the audio, I don't know why.
And I have no idea where this is:
at flash.display::MovieClip/gotoAndStop()
This is the link to the game (the output is the API output, so that wont help, this is just to show the problem)
http://www.newgrounds.com/projects/games/1015606/preview
I made a document with all the code in it (for frame 1), here it is:
https://docs.google.com/document/d/1-jQ7SlQxL7CPL87Vwrl_eEUibgjyVZJ15-Sp4DezHsM/edit?usp=sharing
if anybody needs anything tell me

Related

Flash player stuck at Frame 1 after calling a function

I'm working in a flash CS6 and I'm having a trouble: After calling a function, player freezes at frame 1. This not happend during Ctrl+ENTER preview, but when I play the .swf file published (using flash player or opening it on a web browser, doesn't matter) is when the problem begin.
This is the code:
import flash.display.MovieClip;
var code:int = 0
var temp:int = 0;
var _xmlURL:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=368335%20and%20u=%27c%27";
var _xmlData:XML;
function loadXML(xmlURL:String):void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(_xmlURL);
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadData);
}
function loadData(event:Event):void{
_xmlData = new XML(event.currentTarget.data);
var dataG:XMLList = _xmlData.results.channel.item.elements();
code = dataG[5].#code;
temp = dataG[5].#temp;
trace(code);
trace(temp);
}
loadXML(_xmlURL);
I'm not used to use as3, I don't know if I'm using it right.
As you can see, the code reads an external xml file using "URLLoader" and its method ".load".
Thanks for your help.
BTW, I've already tried to play the published ".swf" file in other PCs (xp, seven, 8), one of them with Windows recently installed (seven).
Most likely (because you're loading in resources from the internet, and it works when you test), this has to do with the security settings of your application.
Go to your publish settings file -> publish settings.
You'll see a drop down labelled Local playback security. Ensure this is set to access network only and not the default acess local only.
This hangs up a lot of people when they first start using flash.
It's always good practice too, to listen not just for the COMPLETE event on your loaders, but also for error events such as:
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandlerFunction);
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, ioErrorHandlerFunction);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandlerFunction);
In your case, it's probably throwing a security error.

Flash Actionscript 3 - sound seeking/playing

I have an audio file which is 4 hours long. I created a standart player to manage my needs - works fine, but you dont seek more than 12180000 miliseconds in position count player stops. If you position the sound to play 12100000 (few seconds earlyear) - plays fine and if it countinues to play without changing the position by code, it is good till the end. I dont get any errors, or any kind of information regarding this kind of issue.
soundChannel = sound.play(12180000); // DOES NOT PLAY, NO ERRORS
soundChannel = sound.play(12100000); // PLAYS FINE, AND CONTINUES TO PLAY TILL THE END
Sound is fully loaded, before playing.
So anybody have any ideas?
this is interesting... I cannot get it to play past 12173943 milliseconds. For me, it works up that that exact number, but anything after that, it won't play. My guess is flash allots a certain amount of memory for sounds and that number right there calculates to the maximum amount of memory allotted for that file. Hopefully someone else can chime in. I am using the MP3 provided by Rummer and this was my test code
import flash.media.*;
import flash.events.*;
import flash.net.*;
var channel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound();
sound.load(new URLRequest("podcast.mp3"));
sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.addEventListener(IOErrorEvent.IO_ERROR, onError);
function soundLoaded(e:Event):void
{
channel = sound.play(12173943);
}
function onError(e:IOErrorEvent):void
{
trace(e);
}
I'm using Flash CS5.5 and exporting for flash 10.2. I would highly consider splitting your mp3s into sections. The first time my SWF loaded, flash hung for a good 10 seconds before it played because of how large the mp3 is.
=============== AS2 version that works
var my_sound:Sound = new Sound();
my_sound.onLoad = function(success:Boolean)
{
if (success)
{
my_sound.start(12180);
}
};
my_sound.loadSound("podcast.mp3", true);

as3 error says "Stream Error", but when loaded manually it's there

I've looked in several other questions, but it just doesn't seem to explain my error.
The error i'm getting is "Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://plustg.com/v2/_inc/_swf/getSavedSelfy.php
at snapshot_fla::MainTimeline/frame1()[snapshot_fla.MainTimeline::frame1:20]"
When going to that URL, it does load. But somehow flash throws a stream error.
For reference, this is all there is on line 20: var selfyXMLLoader:URLLoader = new URLLoader();
And this is the rest of the code:
var selfyXMLLoader:URLLoader = new URLLoader();
var selfyXMLRequest:URLRequest = new URLRequest('http://plustg.com/v2/_inc/_swf/getSavedSelfy.php');
selfyXMLLoader.load(selfyXMLRequest);
selfyXMLLoader.addEventListener(Event.COMPLETE, loadSelfy);
Strange thing here is that when changing it to any other url on ANOTHER website, it will work.
Help would be great.
I think some authentication is needed to get the content of this page. I tried to access it and I was prompted with a login/password box and the message: “You need to be a beta tester to view this page.”
Maybe you've already authenticaded in your browser, that would justify the fact that you can access, but not the Flash.

Try Catch With Sound Element into Flash CS5-as3

Hi All—anyone has any idea why this code doesn’t work?
With other load [example image] work perfect with sound...no :(
mySoundURL = new URLRequest(var+".mp3");
mySoundURLDefault = new URLRequest("default.mp3");
try{
sound.load(mySoundURL);
}catch(e:IOErrorEvent){
trace("Can't load sound: "+e);
sound.load(mySoundURLDefault);
}
this is the error I’m getting:
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error
Thanks and good day!
You do not use try/catch with loaders. Here's what you do instead:
sound.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorEvent);
sound.load(mySoundURL);
private function onIOErrorEvent(e:IOErrorEvent):void{
trace(e);
trace(e.message);
// ^ This will show you the file it tried to load and failed at
e.currentTarget.removeEventListener(IOErrorEvent.IOError, onIOErrorEvent);
e.currentTarget.removeEventListener(Event.COMPLETE, onComplete;
// ^ don't forget to clean up your listeners!
}
The reason for this is, as you've seen, the uncaught error does not tell you anything helpful, such as which sound failed to load, or what the URL you tried to contact was.
I think #Alexander Sobolev is on the right track with his first guess, based on the fact that you still get an error. Handling errors from loaders is just different than handling errors from synchronous code, and try/catch will not help you here.
If you want to try playing an alt sound on fail from the first one, you'd do that in the onIOErrorEvent function.
Other times you'd listen for IOErrorEvent are when using Loader to load a swf or image file
loader.contentLoaderInfo.addEventListener(IOErrorEvent....
Or a URLLoader
urlLoader.addEventListener(IOErrorEvent...
It is not much information in the post, i suggest to check following conditions:
1) Is your var+".mp3" a correct URI? Does it point to the existing file? Just try in the browser - should it find the file?
If you are pointing to the file in internet you should use notation like http://site.com/song.mp3
If you are trying to play a file on your hard drive you should use direct file address like C:/audio/song.mp3
2) If its ok with the URI than maybe file is not in mp3 format.
3) You can try to play with SoundLoaderContext like
var mySoundURL = new URLRequest(var+".mp3")
var context:SoundLoaderContext = new SoundLoaderContext(0, false);
snd.load(mySoundURL , context);

AS3 Error #2044. Once dissmissed the app works fine

I'm working in as3 and my code is producing an error: "Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed."
Other then the fact that the app is producing this error and interrupting users who have a the debug version of the adobe flash player the app works just fine, I "Dismiss All" errors and
I've been debugging the program, stepping through one line at a time, trying to see exactly what it's failing to load and I can figure it out. From what research I've done it seems like the error is caused by urls being wrong or resources not being present, but as I've said, the app works exactly as expected.
here is a link to the app if you have debugger version of flash you'll see when it happens:
http://www.playmatics.com/parents_connect/
Assuming you are loading files off a server, I would suggest looking for server errors on file requests as this could be the source of your problem.
However, you might still want to properly handle the event thrown by the player in order to avoid the error from being displayed:
var loader:Loader = new Loader();
loader.addEventListener(IOErrorEvent.IOError, handleIOErrorEvent);
var urlReq:URLRequest = new URLRequest('srcURL');
loader.load(urlReq);
protected function handleIOErrorEvent(event:IOErrorEvent):void {
trace('handleIOErrorEvent: ' + event);
}
Hope this helps.
UPDATE
Not related to your problem... two files appear as not found – 404 errors – on your server:
http://www.playmatics.com/parents_connect/history/history.js
http://www.playmatics.com/parents_connect/history/history.css