5 Replies Latest reply on Jun 25, 2009 2:57 AM by karthik flex

    How to pass variables from jsp to flex application?

    karthik flex Level 1

      Hi

       

      i need to pass dynamic variables to flex application below is the url

       

      http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postI d=8410

       

      but i am not getting the required output

       

      there is a line

       

      You can create a JSP by saving main.html as e.g main.jsp at the root of your project.

       

      in the above link

      i cannot under stand

       

       

       

      Karthik.k

        • 1. Re: How to pass variables from jsp to flex application?
          Richard_Abbott Level 3

          Karthik,

          The reference to main.html is simply meaning whatever of your pages has the code to instantiate the Flex app (with the AC_FL_RunContent(...) call or other means). The autogenerated page from Flex is always an HTML page, but in many cases you want it as JSP. A simple JSP is exactly the same as HTML except that you can use the <%...%> tags to pull in variables from the server. So simply writing an HTML page (or using the auto-generated one) and then renaming it to ###.jsp and adding the tags where necessary will do the trick. In the example case they have used the username as an illustration, but you can get all kinds of other stuff too depending on your code.

          This is only the most basic example. Your JSP can be much more complicated, but at the end of the day somewhere in the code it will be calling AC_FL_RunContent(...). They are showing you how to use JSP syntax to insert your own content into the FlashVars attribute.

          Richard

          • 2. Re: How to pass variables from jsp to flex application?
            karthik flex Level 1

            hi Richard

             

            then let me explain my problem

             

            i have one project XParameterPasstoFlex

             

            and in the bin-debug we have XParameterPasstoFlex.html

             

            should i need to change in this file by putting the tag

             

            Inside this file i added

             

            AC_FL_RunContent(
                    "src", "playerProductInstall",
                    "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&username=Hello&MMdoctitle='+MMdoctitle+"",
                    "width", "100%",
                    "height", "100%",
                    "align", "middle",
                    "id", "XParameterPasstoFlex",
                    "quality", "high",
                    "bgcolor", "#869ca7",
                    "name", "XParameterPasstoFlex",
                    "allowScriptAccess","sameDomain",
                    "type", "application/x-shockwave-flash",
                    "pluginspage", "http://www.adobe.com/go/getflashplayer"
                );

             

            but i am not getting in the flex application

             

            what can i do

             

            karthik.k

            • 3. Re: How to pass variables from jsp to flex application?
              BennyBeta Level 4

              karthik.k, I would recommend not using the supplied template file and instead simplify the contents of your index.template.html file by using SWFObject.

               

              The following documentation may be helpful in this effort:

              http://www.flexafterdark.com/docs/Flex-HtmlTemplate

               

              Your index.template.html file may end up looking more like this:

               

              <!-- saved from url=(0014)about:internet -->
              <html lang="en">
              <head>
                 <title>${title}</title>
                 <style>
                 body { margin: 0px; overflow: hidden; }
                 </style>
                
                 <script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js"></script>
                 <script type="text/javascript">
                 var flashVars = {
                      userName: "Hello"
                   };
                   var params = {
                      allowFullScreen: "true",
                      allowScriptAccess: "sameDomain"
                   };
                
                 swfobject.embedSWF( "${swf}.swf", "swf", "${width}", "${height}", "10.0.0", "playerProductInstall.swf", flashVars, params );
                 </script>
              </head>
              <body scroll="no">
                
                 <div id="swf">
                    <p>Alternative content</p>
                  </div>
                 
              </body>
              </html>

               

              Note the bolded line of code above setting the flashVar content of userName to "Hello" (as in your example).  The username parameter/flashVar is then available in your application using the below code:

               

              var userName:String = Application.application.parameters.userName;

               

              Let me know if that helps...

               

              Ben Edwards

              • 4. Re: How to pass variables from jsp to flex application?
                Richard_Abbott Level 3

                Karthik,

                the original difficulty you mentioned was to do with using HTML or JSP files at the server to instantiate the swf object - do I take it you have solved this one?

                Ben's suggestion about using the google swfobject code is one way to go. However, if you want to stick with your original method then I sugegst that the problem is that you have put the new flash var in the wrong place. Looks to me as though you have put it in the code block that handles installation of a newer version of the Flash player itself (you have "src", "playerProductInstall"), but of course it should be in the code block to do with your swf file (which would have "src", "my_swf"). Check the JavaScript logic for which bit relates to a need to upgrade the player and which bit relates to your code - it will start with } else if (hasRequestedVersion) {

                Richard

                • 5. Re: How to pass variables from jsp to flex application?
                  karthik flex Level 1

                  hi Guys

                   

                  thank you

                   

                  karthik.k