0

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?

wrkoch
  • 29
  • 4

1 Answers1

1

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)

Carlos Rovira
  • 507
  • 2
  • 11
  • How do I get the HTTPService request to POST to a frame? – wrkoch Aug 24 '20 at 14:05
  • Sorry, don't understand what you mean with "POST to a frame". – Carlos Rovira Aug 25 '20 at 11:39
  • in the code I use the naviagateToURL sends the URLRequest variables to a named frame. I understand the BrowserWindow does that but I need the variables to go as well. What I need to know is how to direct the HTTPService to s named frame – wrkoch Aug 25 '20 at 13:24
  • HTTPService doesn't work as navigateToURL/BrowserWindow. HTTPService has a "complete" event (defined in response code), so when you receive the response you can process the result in a calback function and do whatever you want with it. If you have a `js:IFrame`(for example) inside your Royale app you can pass the result. But maybe what you want to do is to add the HTTPService inside the new Royale page and call from there and then process inside. – Carlos Rovira Aug 26 '20 at 13:32
  • We are using HTML frames with a Cold Fusion page in the target frame to do the data display. I'm surprised there is no way to send FORM data out. Would you know if the BrowserWindow can be modified to pass form data (can't use url string variables) or another method to get data to a target? – wrkoch Aug 27 '20 at 02:32