3 Replies Latest reply on Dec 27, 2010 6:11 AM by Fla. P.

    Send POST parameters to a Flex application

    Fla. P.

      Hi to all,

      I have a big question..I have a flex application that must open a new window containing another flex application, and the first one must send parameters to the second via POST. How can I retrieve the passed parameters from the second application?

      Is it possible?

       

      Best regards,

      Flavio

        • 1. Re: Send POST parameters to a Flex application
          smanisankar

          Hi,

           

            May i know what is the page you are using to embed Flex? i mean html or jsp or aspx?

           

          i can give help you.

           

          Somehow you can send the POST variables using URLVariables in Loader. But for getting it from another Flex you will need jsp or any other file to read and send them into Flex as FlashVars.

           

          thanks,

          Mani

          1 person found this helpful
          • 2. Re: Send POST parameters to a Flex application
            Fla. P. Level 1

            By now the page I use to embed my page is a simple HTML page, the default one crated by FlexBuilder.

            I can also use jsp if it is the solution...or can I send parameters directly from the other Flex application via FlashVars when opening the new window?

             

            Flavio

            • 3. Re: Send POST parameters to a Flex application
              Fla. P. Level 1

              As you suggested I've been able to do the work using a jsp page.

              However, the solution is not trivial


              I wanted to reuse the index.tempate.html page that you found in the html-template folder, without writing a dedicated jsp page.

              Thanks to this article I've been able to reuse that file. The required steps are:


              1. Rename the index.template.html to ${application}${build_suffix}.template.jsp

              2. Add the following lines at the top of the file:

              <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
              <!-- saved from url=(0014)about:internet -->
              <%@ page import="java.net.URLEncoder" %>
              

              3. Retrieve parameters passed via POST (and set on URLRequest using URLVariables) and encode them. For example:

              <%
              String param1= (String) request.getParameter("paramName1");
              String param2= (String) request.getParameter("paramName2");
              param1= param1== null ? "" : URLEncoder.encode(param1, "UTF-8");
              param2= param2== null ? "" : URLEncoder.encode(param2, "UTF-8");
              %>
              

              4. Construct the java version of the FlashVars text:

              String encodedFlashVars = "param1=" + param1+  "&param2=" + param2;

              5. Create a Javascript version of the FlashVars text:

              var flashvarsTxt = "<%= encodedFlashVars %>";
              

              6. Pass such a text to the AC_FL_RunContent object. For example:

              <script language="JavaScript" type="text/javascript">
              <!--
              // Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
              var hasProductInstall = DetectFlashVer(6, 0, 65);
              
              // Version check based upon the values defined in globals
              var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
              
              var flashvarsTxt = "<%= encodedFlashVars %>";
                      
              if ( hasProductInstall && !hasRequestedVersion ) {
                  // DO NOT MODIFY THE FOLLOWING FOUR LINES
                  // Location visited after installation is complete if installation is required
                  var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
                  var MMredirectURL = window.location;
                  document.title = document.title.slice(0, 47) + " - Flash Player Installation";
                  var MMdoctitle = document.title;
              
                  AC_FL_RunContent(
                      "src", "playerProductInstall",
                      "FlashVars", "MMredirectURL="+MMredirectURL+"&MMplayerType="+MMPlayerType+"&MMdoctitle="+MMdoctitle+"&"+flashvarsTxt,
                      "width", "${width}",
                      "height", "${height}",
                      "align", "middle",
                      "id", "${application}",
                      "quality", "high",
                      "bgcolor", "${bgcolor}",
                      "name", "${application}",
                      "allowScriptAccess","sameDomain",
                      "type", "application/x-shockwave-flash",
                      "pluginspage", "http://www.adobe.com/go/getflashplayer"
                  );
              } else if (hasRequestedVersion) {
                  // if we've detected an acceptable version
                  // embed the Flash Content SWF when all tests are passed
                  AC_FL_RunContent(
                          "src", "${swf}",
                          "FlashVars", flashvarsTxt,
                          "width", "${width}",
                          "height", "${height}",
                          "align", "middle",
                          "id", "${application}",
                          "quality", "high",
                          "bgcolor", "${bgcolor}",
                          "name", "${application}",
                          "allowScriptAccess","sameDomain",
                          "type", "application/x-shockwave-flash",
                          "pluginspage", "http://www.adobe.com/go/getflashplayer"
                  );
                } else {  // flash is too old or we can't detect the plugin
                  var alternateContent = 'Alternate HTML content should be placed here. '
                    + 'This content requires the Adobe Flash Player. '
                     + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
                  document.write(alternateContent);  // insert non-flash content
                }
              // -->
              </script>
              

              7. Set the value of FlashVars parameter of the embed tag:

              <embed src="${swf}.swf" quality="high" bgcolor="${bgcolor}"
                     FlashVars="<%=encodedFlashVars%>"
                     width="${width}" height="${height}" name="${application}" align="middle"
                     play="true"
                     loop="false"
                     quality="high"
                     allowScriptAccess="sameDomain"
                     type="application/x-shockwave-flash"
                     pluginspage="http://www.adobe.com/go/getflashplayer">

              8. Read the parameters from the called Flex application contained in Application.application.parameters. For example:

              var param1:String = Application.application.parameters["param1"];
              var param2:String = Application.application.parameters["param2"];
              

               

              That's it!

               

              Hoping that this post could help someone else I send my regards,

              Flavio