A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Read URL variable

  1. #1
    Banned
    Join Date
    Mar 2009
    Posts
    153

    Read URL variable

    How can I read a variable from URL so that it can be used in my swf?

    I have 'main.swf' loaded in 'mainpage.html'. I am using getURL to pass variable from this swf to the URL of another html page......

    Code:
    var getstr="China";
     getURL("secondpage.html?myvar="+getstr,"_blank");



    I have this code in 'secondpage.html' .........
    Code:
    <html>
    <head>
    <title>Second Page that loads page2.swf</title>
    <SCRIPT LANGUAGE="JavaScript" TYPE="Text/JavaScript">
    var myloc=this.location.split("?myvar=")[1];	
    </SCRIPT>
    </head>
    <body>
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="page2" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="page2.swf?ctry="+myloc />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#000000" />
    <embed src="page2.swf?ctry="+myloc quality="high" bgcolor="#000000" width="100%" height="100%" name="page2" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
    </object>
    </body>
    </html>
    As you can see in the above code, I am trying to pass variable 'myloc' into page2.swf.
    'myloc' should contain the variable value of the URL 'myvar'

    This code doesn't seem to work.

    I will be greateful if you could help me.

    Thanks n

  2. #2
    Banned
    Join Date
    Mar 2009
    Posts
    153
    Hello there, any one?

  3. #3
    Junior Member
    Join Date
    Nov 2000
    Posts
    2

    Smile I hope this helps.

    e_tit,

    I think there was a problem with your JavaScript code. I took the liberty of uploading a zip file, which has mainpage.html redirecting to secondpage.html and grabbing the Flash variable from the URL's window.location.search.

    I also changed the name from myvar to myCountry, which is also the name of the dynamic text variable in page2.swf. One thing to note is that the Flash code utilizes the AC_RunActiveContent.js, so it won't run without that file.

    I commented what I did in secondpage.html's JavaScript code, which you can also view below. Good luck, and let me know if you have any other questions!

    Take care,
    Mark
    Code:
    <script language="javascript">
        if (AC_FL_RunContent == 0) {
            alert("This page requires AC_RunActiveContent.js.");
        } else {
        
            // Grab the string in the window.location and place it into a JavaScript variable called "argstring."
            
            var argstring = window.location.search;
            
            if (argstring == "")
                {
                    // If the argstring is empty (myCountry=), then fill the variable with a default country.
                    
                    argstring = "myCountry=China";
                    
                } else {
                
                    // If the argstring is not empty, then remove the "?" and grab the value of myCountry.
                    
                    var argstring=argstring.replace(/\?/,"");
                }
        
        // You can uncomment the following line to test whether the variable was captured to the page correctly.
        
        //alert(argstring);
        
            AC_FL_RunContent(
                'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
                'width', '550',
                'height', '400',
                'src', 'page2',
                'quality', 'high',
                'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
                'align', 'middle',
                'play', 'true',
                'loop', 'true',
                // Add the FlashVars variable and the Javascript string.
                'FlashVars', argstring,
                'scale', 'showall',
                'wmode', 'window',
                'devicefont', 'false',
                'id', 'page2',
                'bgcolor', '#ffffff',
                'name', 'page2',
                'menu', 'true',
                'allowFullScreen', 'false',
                'allowScriptAccess','sameDomain',
                'movie', 'page2',
                'salign', ''
                ); //end AC code
        }
    </script>
    Attached Files Attached Files
    Last edited by MyFriendIsATaco; 04-29-2009 at 08:02 PM. Reason: Please wrap code blocks in [CODE] tags. :)

  4. #4
    Banned
    Join Date
    Mar 2009
    Posts
    153
    thanks a ton. I will take a look at it and let you know in case of any doubts.

    Thanks again

  5. #5
    Junior Member
    Join Date
    Nov 2000
    Posts
    2
    You're welcome! Good luck and have fun!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center