8 Replies Latest reply: Oct 26, 2011 3:45 AM by willise414 RSS

    Flashvars

    willise414

      I need some guidance on using flashvars to load separate URL's.

       

      I have a website that has two links on it, LinkA and LinkB. Both of these links require the user to login, so they both point to my login.swf and login.php.

       

      One the user logs in, how can I let the login SWF know which link to direct the user to?

       

      I know I can use separate SWF's for each link on the main page, but as I add more links, it will become very cumbersome, so I'd like to do it with flashvars.

       

      So in essence, I want to pass either LinkA or LinkB to the login SWF, and then once the user completes the login, redirect them to the appropriate content based on their LinkA or LinkB selection initially.

       

      I hope that makes sense!

       

      Thank so much!!

        • 1. Re: Flashvars
          Flex harUI Adobe Employee

          You can add different flashvars to the htmlwrappers, or pass information on the URL to the SWF.  Both will get picked up and be available in the Application.parameters.

          • 2. Re: Flashvars
            willise414 Community Member

            Hi there,

             

            Thanks for the quick reply.

             

            I understand that the flashvars will get picked up by the Application.parameters tag, but It would really help if I could see an example. How do I set it up so that the original HTML page sends the link to the flashvars?

             

            THanks again!!

            • 3. Re: Flashvars
              Flex harUI Adobe Employee

              In the index.template.html, there is the line:              var flashvars = {};

               

              Populate that object with something useful like

                  var flashvars =

               

              And the Application.parameters.link will be “linkA”

              • 4. Re: Flashvars
                willise414 Community Member

                You'll have to forgive my ignorance here, but I can't wrap my head around this.

                 

                In the login.html, I will set up the flashvars to something like this:

                 

                <param name = flashvars value="linkA=URLofLinkA&linkB=URLofLinkB">

                 

                That doesn't seem correct to me.

                 

                In the Flex login app, I would put Application.application.parameters.LinkA

                 

                I guess my understanding of flashvars is very limited. I can't seem to understand how the link that the user clicks on in a pure HTML only page will populate a flashvar.

                 

                Sorry for my ignorance.

                • 5. Re: Flashvars
                  Flex harUI Adobe Employee

                  I think we don’t understand the problem.  It might be that you don’t want to use flashvars at all and just use URL parameters.  In the links you would put in something like:

                   

                   

                  Go to A
                  Go to B

                   

                  Then if login.html loads login.swf, you would use BrowserManager in your app to parse off the link from the URL.  See the doc examples for BrowserManager.

                  • 6. Re: Flashvars
                    willise414 Community Member

                    OK,

                     

                    I've been trying to figure this out for the last several days to no avail.

                     

                    Here is an example of what I have so far:

                     

                    My URL of the HTML page is www.mydomain.com?page=google

                     

                    My understanding is that the "?page=google" sets teh URL variable to be passed to flex.

                     

                    This is my MXML application to test it:

                     

                    <?xml version="1.0" encoding="utf-8"?>

                    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                     xmlns:s="library://ns.adobe.com/flex/spark"

                                                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">

                              <fx:Declarations>

                                        <!-- Place non-visual elements (e.g., services, value objects) here -->

                              </fx:Declarations>

                              <fx:Script>

                                        <![CDATA[

                                                  import flash.net.*;

                                                  import flash.net.navigateToURL;

                     

                                                  import mx.core.FlexGlobals;

                     

                     

                     

                     

                                                  [Bindable]

                                                  private var page:String;

                     

                                                  private function init():void

                                                  {

                     

                     

                                                            page = FlexGlobals.topLevelApplication.parameters.page;

                     

                                                            output.text = "test: " +page + "\n"

                     

                                                  }

                     

                                                  protected function redirect(event:MouseEvent):void

                                                  {

                                                            page = FlexGlobals.topLevelApplication.parameters.page;

                     

                                                            var src:URLRequest = new URLRequest("http://www.google.com");

                                                            var temp:URLRequest = new URLRequest("http://www.msn.com");

                                                            var last:URLRequest = new URLRequest("http://www.cnn.com);

                     

                                                            if (parameters.page == "google")

                                                            {

                                                                      navigateToURL(src, "_blank");

                                                            }

                     

                                                            else

                                                                      navigateToURL(temp, "_blank");

                     

                     

                     

                                                  }

                     

                     

                                        ]]>

                              </fx:Script>

                     

                     

                              <s:Button x="88" y="70" label="FlashVar" id="flashvar" enabled="true" click="redirect(event)" />

                     

                              <s:TextArea id="output" width="300" height="76" x="264" y="70"/>

                              <s:Label x="88" y="231"  width="101" height="37" text="{page}"/>

                     

                     

                     

                    </s:Application>

                     

                    In my text area, the flashvar is never appearing, so unless my coding is wrong, the variable os not getting sent to the application. When I click the button, I get redirected to msn.com - another clear indication my variable is not getting received.

                     

                    Can anyone see what I'm doing wrong here?

                     

                    Thanks so much!!

                    • 7. Re: Flashvars
                      Flex harUI Adobe Employee

                      I think your first assumption isn’t true.  Hitting www.mydomain.com/index.html?page=google only sets URL params for the html page.  In the html, a SWFObject is created and given flashvars and other parameters and there is no default behavior that copies the URL params from the html to the SWFObject.  You can write JS to do so, or you can change to use BrowserManager.  Then you’d hit www.mydomain.com/index.html#page=google and the BrowserManager code would pick up the page=google and let you handle it in an event.  You would not use Application.parameters.

                      • 8. Re: Flashvars
                        willise414 Community Member

                        OK,

                         

                        I'll try to rewrite the code and see if it works.

                         

                        First, I have to research BrowserManager

                         

                        Thanks