AS3 Flash URLRequest not working upon export - actionscript-3

This simple login form works within the test environment of CS6 (Flash 11.4) but upon exporting does not work. I've narrowed down the issue to the actual URLRequest not working properly. Hopefully somebody can shed some light!
Many thanks, Nick :)
AS3
login.loginSubmit.addEventListener(MouseEvent.CLICK, function(){
if(login.loginPassword.text!="Password" && login.loginPassword.text!=""){
login.loginSubmit.enabled = false;
// Begin URL setup for login
var loginVariables:URLVariables = new URLVariables("email="+login.loginEmail.text+"&password="+login.loginPassword.text);
var loginRequest:URLRequest = new URLRequest();
loginRequest.url = "login.php";
loginRequest.method = URLRequestMethod.POST;
loginRequest.data = loginVariables;
var loginLoader:URLLoader = new URLLoader();
loginLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
loginLoader.addEventListener(Event.COMPLETE, loginHandler);
function loginHandler(event:Event):void {
if(loginLoader.data.passed=="true"){
var hideInitial:Tween = new Tween(uiInitial, "x", Strong.easeOut, 6, -315, 0.5, true);
hideInitial.addEventListener(TweenEvent.MOTION_FINISH, function(){
member.data.email = loginLoader.data.email;
member.data.fname = loginLoader.data.fname;
member.data.lname = loginLoader.data.lname;
member.flush();
});
}else{
trace("error");
}
}
// Send PHP/SQL request
loginLoader.load(loginRequest);
}
});

You need to enable the network access for your published SWF. Go to Publish Settings for Flash (.swf) and Set the "Local playback security" settings to "Access Network Only".

Turns out that there is both a local and external URLRequest, causing trouble with the settings. I've made both the same (external) and of course hosted them on the same domain as the Flash, now works.

Related

Air to Air localconnection

I am trying to connect two Air Application using LocalConnection. It works when I open as SWF and EXE(published) but when I publish it to Air files they doesn't work. I am creating one interactive screen that send command to another Air Application(Projector). This few lines on code will only appear of "frame one".
Sending:
var sending_lc:LocalConnection;
sending_lc = new LocalConnection();
Receiving:
var receiving_lc:LocalConnection;
receiving_lc = new LocalConnection();
receiving_lc.connect("my_lc_as3");
receiving_lc.client = this;
Please refer to this doc http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/LocalConnection.html
To make LocalConnection work between AIR apps, allowDomain() needs to be called.
For example, in your case:
// For receiving_lc
// Here receiving_lc is an Air app with app Id = com.sample
receiving_lc.allowDomain('app#com.example');
receiving_lc.connect("my_lc_as3");
// For sending_lc
sending_lc.send('app#com.sample:my_conn', 'my_method');
Thank you KevinVFX and akmozo.
It's working now and this is the code.
Sending:
var sending_lc:LocalConnection;
sending_lc = new LocalConnection();
sending_lc.send("app#APPIDReceiving:my_lc_as3", "my_method");
Receiving:
var receiving_lc:LocalConnection;
receiving_lc = new LocalConnection();
receiving_lc.allowDomain("app#APPIDSending");
receiving_lc.connect("my_lc_as3");
receiving_lc.client = this;
function my_method():void{
trace("linked");
}

flex 4.6 : How to cache image captured using PersistenceManager

Im beginner in Flex mobile application , my issue is the app restart then i used PersistenceManager to solve it, but when i take an image with camera i cannot hold the image if the app restart then how to hold all image captured when user click to save button i think it will be in the imagecaptured method but it doesn't work the app restarted and camera app is opened to take image method is
public function imagecaptured(event:MediaEvent):void
{
//submitButton.enabled = false;
antherImg.label = "please wait to detect your location";
imagepromise = event.data;
imgBorder.source = imagepromise.file.url;
//values to send
var imgURL:Object = imagepromise.file.url;
var imgName:Object = imagepromise.relativePath;
//save Persistence
var saveManager:PersistenceManager = new PersistenceManager();
saveManager.setProperty("url", imagepromise.file.url);
saveManager.setProperty("name", imagepromise.relativePath);
}
and when page creation (creationComplete)
public var loadManager:PersistenceManager = new PersistenceManager();
if(loadManager.load())
{
var savedData:Object = saveManager.getProperty("url");
var savedData:Object = saveManager.getProperty("name");
}
Please help , Thanks in advance

URLrequest cache response not working

I want to cache the response of a urlRequest for offline usage in Adobe Air. When I compile for flash player the cache works and I get the response even when I disconnect the network, but when I compile for Adobe Air I get error. PS: useCache and cacheResponse dose not work!
stage.addEventListener(MouseEvent.CLICK , callReq)
var loader:URLLoader = new URLLoader()
function callReq(e:Event):void
{
//URLRequestDefaults.manageCookies = true;
//URLRequestDefaults.useCache = true;
var r:String = "http://onecom.no/presentation_json.php?what=get_slides&slide_id[]=2540"
var urlRequest:URLRequest = new URLRequest(r)
// urlRequest.cacheResponse = true
// urlRequest.useCache = true
urlRequest.url = r
loader.addEventListener(Event.COMPLETE , Comp)
loader.load(request)
}
function Comp(e:Event):void
{
trace( e.target.data)
}
Air can not use the browsers cache. I had to build my own cache class that saves all URLRequest responses to a Shared Object and loads them if there is no internet connection
save them to variables and store them in the local SQLlite database on your device/computer?...
Using local SQLlite on device

FileReference: post file without browsing

I am trying to upload a file to the server. I'm doing it like this:
var fileRef:FileReference = new FileReference();
fileRef.addEventListener(flash.events.Event.SELECT, selectHandler);
fileRef.addEventListener(flash.events.Event.COMPLETE, completeHandler);
fileRef.addEventListener(ProgressEvent.PROGRESS, normalprogressHandler);
fileRef.browse();
function selectHandler(event:flash.events.Event):void
{
var params:URLVariables = new URLVariables();
params.date = new Date();
params.ssid = "94103-1394-2345";
var request:URLRequest = new URLRequest("http://www.test.com/Uploads");
request.method = URLRequestMethod.POST;
request.data = params;
fileRef.upload(request, "Custom1");
}
function completeHandler(event:flash.events.Event):void
{
trace("uploaded");
}
function normalprogressHandler(event:ProgressEvent):void
{
var percent:Number = Math.floor((event.bytesLoaded * 100)/ event.bytesTotal );
trace(percent+"%");
}
Would it be possible to upload a file but without browsig for it? I want to decide myself what file to upload instead of the user performing a browse first
You can't do that with FileReference which has the following limitations (reference):
The load() and save() APIs can only be called in response to user
interaction (such as a button click).
The locations of the loaded and save files are not exposed to
ActionScript.
The APIs are asynchronous (non-blocking).
Clearly, it would represent a major security risk if the Flash player was arbitrarily allowed to upload anything from your local file system to a remote server.
If you're trying to upload from an AIR app, you can do what you're trying to do with the File class.

Sending POST variables via an AIR application

I'm trying to send data via POST, since it's far too long to send via GET.
Here's the code I'm using...
pdfUrl.method = URLRequestMethod.POST;
var vars:URLVariables = new URLVariables();
vars.html = data;
pdfUrl.data = vars;
navigateToURL(pdfUrl);
The problem is that it always sends as GET, and the data in vars.html is too long for my server to receive.
To make matters worse, it seems like AIR can only send GET via navigateToURL.
The issue with this is, I need to open a new browser window and send the POST data so that a script on my server can create a PDF file for the user.
What workarounds are there for this?
I'm not aware of any way to open a new browser window with a POST request, with GET being the default HTTP method used to open pages (which makes sense, really). An alternative, however, would be to POST the data using a simple HTTP request in AIR and once you get a response to the POST request in AIR, you can open a new browser window using a GET request.
So:
POST to your server directly from AIR.
Have your server return some kind of value that you can use in step 3.
Open a new browser window using navigateToURL and attach the value you got from step 2 to the URL.
This should work well, I think.
// Upload MP3-Byte-Array
private function uploadFile():void
{
var uploadURL:URLRequest = new URLRequest();
uploadURL.url = "myfile.php?var1=var1Value&var2=var2Value";
uploadURL.contentType = 'application/octet-stream';
uploadURL.method = URLRequestMethod.POST;
uploadURL.data = heavyDataThatyouWantToPass;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, completeHandler);
urlLoader.load(uploadURL);
}
private function completeHandler(event:Event):void
{
var loader:URLLoader = URLLoader(event.target);
}
myfile.php will be like this:
<?php
$var1 = $_REQUEST['var1Value'] ;
$var2 = $_REQUEST['var2Value'] ;
$heavyData = $GLOBALS[ 'HTTP_RAW_POST_DATA' ];?>