Recode Flex URLRequest and navigateToURL form emulation to Royale JS

295 Views Asked by At

I have a bunch of Flex pages I need to convert to get rid of the flash player and have been unable to see how to replicate this code just using the javascript.

The Flex code gathers up data and sends it in a POST to a Cold Fusion page in another frame (named FrameData). Cold Fusion accesses the data from a FORM variable (FORM.mydata1, FORM.mydata2, etc.).

var RequestSite:URLRequest;

OutputPageValues.OutputType = 5;
OutputPageValues.mydata1 = "2";
OutputPageValues.mydata2 = "test";

RequestSite = new URLRequest("pageurl.cfm"));
RequestSite.data = OutputPageValues;
RequestSite.method = URLRequestMethod.POST;

navigateToURL(RequestSite, 'FrameData');

How do I emulate this construct in Royale? Is there another way to do this?

1

There are 1 best solutions below

5
Carlos Rovira On

equivalente code for URLRequest:

var u:URLRequest = new URLRequest("http://domain.foo");
navigateToURL(u,"_blank");

in Apache Royale is BrowserWindow:

import org.apache.royale.core.BrowserWindow;

var u:String = "http://domain.foo";
BrowserWindow.open(u, "_blank");

To pass variables you need to do via GETmethod: "http://domain.foo?variable=" + key.

To use POST method use HTTPService class from Network SWC instead:

import org.apache.royale.net.HTTPConstants;
import org.apache.royale.net.HTTPService;
import org.apache.royale.net.URLVariables;

// add the variables to send
var urlVars:URLVariables = new URLVariables();
urlVars.set("variable", key);

// create the httpservice instance
var service:HTTPService = new HTTPService();
service.url = "http://domain.foo";
service.method = HTTPConstants.POST;
service.addEventListener("complete", resultCallback);
service.addEventListener("ioError", faultCallback);

// add the variables
service.contentData = urlVars;

// trigger the service
service.send();

Optionally in case you need to deal with CORS you can add CORSCredentialsBead bead to the HTTPService:

service.addBead(new CORSCredentialsBead(true));

(Note: code is untested, please report if all is ok so we can improve this response and code snippet, thanks)