How to just run an URL(php) with as3? - actionscript-3

I am currently using:
var urlLoader:URLLoader = new URLLoader();
var url:String = GameConfig.SITE_DOMAIN+"/insert_tracking_event.php?hash="+GameConfig.hashTracking+"&event_id="+event+"&check=xxxxxxx";
urlLoader.load(new URLRequest(url));
It works one time and even if i reload the page it somehow dont run the url again. The only way for it to work again is cleaning cache and reloading the swf.
Is there other method or way to do it? I dont need any responses just run the url.
Thanks

Well #user3120770 gave me the answer, all i needed was to send a random num in the url so it ll never get blocked.
"&randomnum=xxxxx"
Thanks

Related

Flash sandbox not enabling me getting JSON data from server - AS3

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.

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.

Cannot use URLRequestMethod different from POST GET in ActionScript

I'm trying to get the head of a page without downloading the whole thing, because it's too heavy and I just need the header information.
The code is this:
var resource:String = "<myResource>";
var urlRequest : URLRequest = new URLRequest(resource);
urlRequest.method = URLRequestMethod.HEAD;
var requestLoader:URLLoader = new URLLoader();
requestLoader.load(urlRequest);
It works if I use either POST or GET, but not HEAD, PUT or DELETE.
I don't know how to solve it or if it has been deprecated.
According to the docs, the constant is still valid but in the first line it says that it is only to distinguish between GET and POST.
Edit:
Finally I ended up doing the request in Javascript and calling it from actionScript. Maybe it is not a great solution, but it works fine.

Need alternative to POST data using navigateToURL that works with Pepper Flash plugin

As most people know, Google messed several flash applications after starting using Pepper Flash plugin in Chrome.
I'm getting the same problem, but it can't be solved with external interface call, as I need to post data using POST, to a php file.
My application basicaly takes a screenshot, and post to a php file. Worked fine before, but now with Pepper Flash, nothing happens.
This is the piece of code that POSTs the data.
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(URL_TO_THE_PHP_FILE, "_self");
Is there a workaround for this? My website that uses this application have thousands visitors daily, and most users woudn't know how to disable pepper flash.
thanks.
To upload image, you will need URLLoader, image encoding algorithm, and some contract(names of variables in POST's body, encoding algorithm, etc) with you server-side
var urlRequest : URLRequest = new URLRequest();
var urlLoader : URLLoader = new URLLoader();
var urlVars : URLVariables = new URLVariables();
//Take from the image bytes, for example with JPEGEncoder
//Endoce ByteArray for example with Base64
//If image is big, you can split on several parts
urlVars.image = Base64.encode(imageData);
urlRequest.url = $snapshotUploadURL;
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = urlVars;
// create the image loader & send the image to the server;
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.load(urlRequest);
BloodyCrypto is very helpful library for this task.

Is it possible to retrieve xml from server, save to device and use that local file for my HTTPService url?

I have an app that retrieves XML From a server I run... Im trying to limit the calls to the server (if possible) to improve responsiveness of the app and decrease the likelihood that the user will get errors if the data stream doesnt make the trip successfully for whatever reason -- i get some intermittent network monitor errors, it could be due to some wifi channel conflicts I think I have, but its still is a potential weak point in the overall process and if I can work around that need to call to the server each time the user performs an 'action' within the app.
what I'd like to do is use the local storage on the device to (upon launch of the app) retrieve and save the XML data, then change my httpservice url the local file.
I have some code I used before to successfully write and read config settings to a local text file, so Im pretty sure this can be achieved, just not sure how exactly to go about it.
thanks for any light someone can shed on this or any code examples anyone can share.
Load it by default from the applicationStorageDirectory if it doesnt exist donwload and save the xml to the applicationStorageDirectory
to load:
var xmlFile:File = File.applicationStorageDirectory.resolvePath("data.xml");
if (xmlFile.exists)
{
var fileStream:FileStream = new FileStream();
fileStream.open(xmlFile, FileMode.READ);
var xml:XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));// you will want to declare outside this scope, its just for show
fileStream.close();
}else{
downloadAndSaveXML();// if it doesnt exist dowload it then save it and call load again!
}
to save:
//download .xml first and save in the onComplete handler, im calling the file "xml"
var file:File = File.applicationStorageDirectory.nativePath("data.xml");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes(xml.toXMLString());
stream.close();
get the idea?
You will also need this compiler argument so the HTTPService doesnt look online for the xml
-locale en_US -use-network=false
You could not bother with dowloading the file in the firstplace and just embed it in the Application
here a link to the topic