« Congrats to Open Flex! | Main | Win free AIR Books »
Get IPAddress into Flash
| By Rich Tretola | August 7, 2008 | Print This Post
|
| 1,989 views |
I have had a few people ask how to read the users IPAddress from within Flash. The way I do this is to use my application server to write the IPAddress into a flash var which I then read from flash. This is obviously open to spoofing if the user wants to play games as the IPAddress is displayed within the page source however it fulfills my needs.
For example my Index.jsp looks something like this:
- <%
- String flashIPAddress=request.getRemoteAddr();
- %>
- </head>
- <html lang="en">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title></title>
- <%
- String flashIPAddress=request.getRemoteAddr();
- %>
- <script src="AC_OETags.js" language="javascript"></script>
- </head>
- <body scroll='no'>
- <script language="JavaScript" type="text/javascript">
- <!--
- AC_FL_RunContent(
- "src", "temp",
- "width", "100%",
- "height", "100%",
- "align", "middle",
- "id", "temp",
- "quality", "high",
- "bgcolor", "#869ca7",
- "name", "test",
- "flashvars","flashIPAddress=<%= flashIPAddress %>
- ",
- "allowScriptAccess","sameDomain",
- "type", "application/x-shockwave-flash",
- "pluginspage", "http://www.adobe.com/go/getflashplayer"
- );
- // -->
- </script>
- <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
- id="temp" width="100%" height="100%"
- codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
- <param name="movie" value="test.swf" />
- <param name="quality" value="high" />
- <param name="bgcolor" value="#869ca7" />
- <param name="allowScriptAccess" value="sameDomain" />
- <param name="flashvars"value="flashIPAddress=<%= flashIPAddress %>"/>
- <embed src="test.swf" quality="high" bgcolor="#869ca7"
- width="100%" height="100%" name="temp" align="middle"
- play="true"
- loop="false"
- quality="high"
- allowScriptAccess="sameDomain"
- flashVars="flashIPAddress=<%= flashIPAddress %>"
- type="application/x-shockwave-flash"
- pluginspage="http://www.adobe.com/go/getflashplayer">
- </embed>
- </object>
- </noscript>
- </body>
- </html>
Notice that I grab the IPAddress in the head and then pass it in 3 different places within the flash embed and script code:
Now within my application I simply refer to this var like this:
- var ipAddress:String = Application.application.parameters.flashIPAddress;
You could certainly take the same approach within a ColdFusion, ASP, or PHP environment as well.
Topics: Flex |








(1 votes, average: 4 out of 5)
August 10th, 2008 at 9:39 pm
hello here is a php code and a flex example.
MXML CODE:
PHP CODE:
August 14th, 2008 at 9:24 pm
so,first way is good if off line;and if the client on line,the seconed is better.