3 Replies Latest reply on Aug 8, 2007 10:18 AM by ntsiii

    receive URL variables in Flex

    187_2007 Level 1
      I have this URL that is in an email :

      http://mywebpage/HR/bin/HR.html?ID=127


      This sends me to my FLEX application. From there I want to get the ID in the flex app.

      I've tried:
      Alert.show(ObjectUtil.toString(Application.application.parameters));

      but it gives me some weird stuff. I also tried using

      Alert.show(ObjectUtil.toString(Application.application.parameters.ID));

      and it returned:
      (NULL)

      What am I doing wrong here? Anyone know? YEs, this is in Actionscript 3

        • 1. Re: receive URL variables in Flex
          ntsiii Level 3
          A static html page has no processing capabilities to take the request argument and pass it into Flex.

          You will need some javascript that can take the argument and pass it to Flex in the flashvars.

          There are some examples out there. Check the archives and google, post back if you do not find a solution.

          Tracy
          • 2. receive URL variables in Flex
            levancho Level 3
            One way is to :

            in your bin directory open main.html (or whatever html that you have which wrapps flashplayer) inside there locate :
            ------
            } else if (hasRequestedVersion) {
            // if we've detected an acceptable version
            // embed the Flash Content SWF when all tests are passed
            AC_FL_RunContent(
            "src", "main",
            "width", "100%",
            "height", "100%",
            "align", "middle",
            "id", "main",
            "quality", "high",
            "bgcolor", "#ffffff",
            "name", "main",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", " http://www.adobe.com/go/getflashplayer"
            );
            }

            -----


            and replace with

            -------

            } else if (hasRequestedVersion) {
            // if we've detected an acceptable version
            // embed the Flash Content SWF when all tests are passed

            var httpParams = location.href.indexOf('?') != -1 ? location.href.split ('?') : '';

            AC_FL_RunContent(
            "src", "main",
            "width", "100%",
            "height", "100%",
            "align", "middle",
            "id", "main",
            "quality", "high",
            "bgcolor", "#ffffff",
            "name", "main",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", " http://www.adobe.com/go/getflashplayer",
            "flashvars",httpParams );
            }

            ------

            now you have http parametes passed in as flashvars (i wonder why this is not done by default in the autogenerated script?)

            P.S instead of ...

            var httpParams = location.href.indexOf('?') != -1 ? location.href.split ('?') : '';

            you can also do :
            <!--
            var httpParams =document.location.search;

            if (httpParams [0]='?')
            {
            httpParams =httpParams .substr(1, httpParams .length-1);
            }
            • 3. Re: receive URL variables in Flex
              ntsiii Level 3
              Excellent example.

              And you now access those parameters in Flex using Application.application.parameters object:
              var sId:String = Application.application.parameters.ID; //should contain 127

              Tracy