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.
Related
I'm trying to help out a client with an Adobe AIR application that suddenly stopped working on Mac OS Sierra. I haven't developed the app myself, so I am trying to do my best to solve the problem. It's essentially a Flex application written in Actionscript 3. When I was debugging I can see that I am getting the following error:
[ERROR] Error #2032: Stream Error.
The way the application works is that it first makes a web request to the server and gets an XML with a number of songs. No problem there.
After that the application downloads the first song in the XML result and starts playing.
When the first song starts playing the application then downloads the second song in the XML-list, when that download is finished it starts downloading the next one and so forth. The files being downloaded seems to be rather large, a couple of MB's.
So the first download works just fine, but all the other track downloads fails with Stream Error #2032. It seems I dont get any response headers from the failed requests, only the first one. I have a crossdomain.xml on the server.
This app works just fine on Mac OS X El Capitan and Windows, but with Sierra I am getting this error. The code is not that complex, it makes an API URL Request with an URLLoader and saves the file to disk. I have also tried using URLStream instead, same issue.
This is some of the code for example:
public function downloadTrack(track:Object, storeName:String, apiKey:String):void {
this.setCurrentTrack(track);
this.urlParameters.storeName = storeName;
this.urlParameters.keystring = apiKey;
this.urlLoader = new URLLoader();
this.urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
this.urlRequest = new URLRequest("/api/" + 'download/' +
this.currentTrack.id + "?time=" + new Date().getTime());
this.urlRequest.method = URLRequestMethod.POST;
this.urlRequest.data = this.urlParameters;
this.addEventListeners();
this.urlLoader.load(this.urlRequest);
}
private function loaded(e:Event):void {
this.fileData = e.target.data;
writeFile();
}
private function writeFile():void {
var filePath:String = this.currentTrack.md5 + '.ogg';
var cacheFile:File = this.downloadDirectory.resolvePath('.' + filePath);
this.fileStream.addEventListener(Event.CLOSE, saveReady);
this.fileStream.openAsync(cacheFile, FileMode.WRITE);
this.fileStream.writeBytes(fileData,0,fileData.length);
this.fileStream.close();
}
In the addEventListeners()-method, event-listeners for the URLLoader is added, and it's the urlloader that fires the IOError.
A weird thing that has happened twice is that the app suddenly starts to work as normal and downloads all of the files successively. Then after a couple of minutes it starts acting up again and nothing works. I am really having a hard time to understand where the error lies. I am no Adobe AIR/Flex-expert, so maybe you can point me in the right direction? I am pretty close to giving up on this one.
Thanks!
Try to change the destination, probably you don't have permissions to
write there.
Use the latest AIR SDK
Would be much better if you will share the project where it reproduced so I could check on my machine
My app loads an external URL (XML file) every 30 seconds. The app is set in startup so it starts whenever the system starts. The URLLoader stucks on the "open" event after every reboot of system. If I close the app and relaunch it, it works perfectly fine. I have added all event listeners on this URLLoader to see where is the problem. Every time it stuck at URLLoader open event. This is the straight forward code, does not seem to be any complexity. I have also tried exporting it with "Access network only" in publish settings.
private var liveFeedLoader:URLLoader = new URLLoader();
private var feedUpdateTimer:Timer = new Timer(30000);
private function init(e:Event):void {
liveFeedLoader.addEventListener(IOErrorEvent.IO_ERROR, liveFeedLoaderErrFx);
liveFeedLoader.addEventListener(Event.COMPLETE, liveFeedLoaderFx);
feedUpdateTimer.addEventListener(TimerEvent.TIMER, checkForUpdate);
liveFeedLoader.load(new URLRequest("https://s3-us-west-2.amazonaws.com/abcd/XYZ.xml"));
feedUpdateTimer.start();
}
I have a game written in AS3 on top of Adobe AIR. Now that I've found a publisher for the game, I need to load an external swf to display advertisements (cpmstar). Unfortunately it hasn't been straightforward, and I can't seem to get any advertisements to display on the stage. I'm wondering if I'm doing something wrong. Here's my code:
Security.allowDomain("server.cpmstar.com");
var cpmstarViewSWFUrl:String = "http://server.cpmstar.com/adviewas3.swf";
var cpmstarLoader:Loader = new Loader();
var allowSWF:LoaderContext = new LoaderContext( false, ApplicationDomain.currentDomain, null );
allowSWF.allowCodeImport = true;
var urlRequest:URLRequest = new URLRequest(cpmstarViewSWFUrl + "?contentspotid="+ < my ID > );
cpmstarLoader.load( urlRequest, allowSWF );
addChild( cpmstarLoader );
With the above, I see the url request successfully complete ( I can also see the 200 success response in Chrome ) , but I never see any content added to my stage. I've also tried, with no success, loading the distant URL with URLLoader and then reloading it through loadByte as described here: AIR Loading server hosted swf into same sandbox
If the code above looks okay, could the advertisers swf file be doing something that isn't allowing it to play nicely with this code? If so, what?
Thanks in advance.
i'm setting up a local SWF file that has to display some JSON data retrieved from a remote web server in some dynamic text fields.
Code:
Security.allowDomain("api.yourserver.com");
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://api.yourserver.com/yourendpoint");
request.method = URLRequestMethod.GET;
request.contentType = "application/json";
loader.load(request);
loader.addEventListener(Event.COMPLETE, decodeJSON);
function decodeJSON(event:Event):void{
var loader:URLLoader = URLLoader(event.target);
var Info:Object = JSON.parse(loader.data);
cont.textfield1.text = Info.text.field1;
cont.textfield2.text = Info.text.field2;
cont.textfield3.text = Info.text.field3;
}
Control > Test - It works. When run standalone it doesn't. I get the 2028 error (sandbox violation).
What i tried:
The LoaderContext method explained here on StackOverflow but i get a 2124 error (Loaded file is an unknown type - seems like the Loader method can only be used with stuff like SWF or medias like JPG etc.);
Setting local playback as described always here on StackOverflow but it didn't help;
Setting up and exception in the Global Flash Player Trust directory as explained here but got the 2028 again;
Anyone who was able to overcome this and willing to explain how or at least pointing in the right direction?
Thanks in advance!
I think that your current published file has just assess to local files only and not network ones, that's why you got security #2028 error.
To avoid that, you can change the Local playback security for your published swf from the Publish Settings to Access network only :
If you still get security errors when testing locally ( like #2048 error ), take a look on my answer of this question to add your local swf file to the trusted locations ...
Hope that can help.
I have to execute multiple navigateToURL in an swf on file:// protocol (so I can't use ExternalInterface).
Unfortunately, I can't set this swf as trusted.
I am using this code:
var urls:Array = [
'file:///tmp/1',
'file:///tmp/2',
'file:///tmp/3'
];
var timer:Timer = new Timer(300, urls.length);
timer.addEventListener(TimerEvent.TIMER, onTimer);
function onTimer(e:TimerEvent):void {
navigateToURL(new URLRequest(urls[timer.currentCount - 1]), '_blank');
}
timer.start();
Unfortunately, now flash when navigateToURL() is used in an untrusted swf, ask for permissions in a popup like this
http://i.stack.imgur.com/pWQuB.jpg
with this code, this popup appears every time navigateToURL is executed, in my case 3 times, and it makes the program unusable. I thought flash was designed to ask for permissions just once.
There's a solution to avoid this behaviour?