Flex gets the instance code for the client IP and computer name through JS

  • 2020-03-29 23:55:20
  • OfStack

First of all, getting it JS is not calling webservices and httpservices.

      In each of our FLex web projects, have such a folder bin - debug, there is an index. The HTML file, my understanding is that the first web page run, MXML files will be compiled as SWF, how SWF show in the browser, is through the HTML files, equivalent to the HTML file embedded in a SWF object components. www.jb51.net

        So, I personally think it's possible to write js code in this HTML to get the IP address. So the following code appears.

Add the script tag in index.html, the actual code is as follows:


<script type="text/javascript">
function getClientPcName()
{ 
    //Alert (" please set "initialize and script run for an ActiveX control that is not marked as secure" in your browser Internet option to "enable"! /n/n then refresh this page to login!" );
    ///window.onerror = killErrors; +"/"+WshShell.UserName;
  var WshShellPcName = new ActiveXObject("WScript.Network");
  var ComputerName = WshShellPcName.ComputerName ;
  //Add a trust site (HTTP: successive 192.168.1.5)
  //alert(ComputerName); 
    return ComputerName;
  }
  function getClientIp()
  {
  var WshShellIp = new ActiveXObject("rcbdyctl.Setting");
       var ip = WshShellIp.GetIPAddress;
       return ip;
}
</script> 

So the equivalent of the background code to get IP and pcname is written.

How to call in flex, then use the flex of the class: flash. External. The ExternalInterface.

For the ExternalInterface class, adobe explains it this way:

The ExternalInterface class is the external API, an application programming interface that enables direct communication between the ActionScript and Flash Player containers, for example, an HTML page that contains JavaScript. Adobe recommends using ExternalInterface for all communication between JavaScript and ActionScript.

In Flash Player, you can use JavaScript from an HTML page to call ActionScript functions. The ActionScript function can return a value that JavaScript immediately receives as the return value of the call.

This function replaces the fscommand() method.

You can use the ExternalInterface class in the following combination of browser and operating system:

  . - + * / /

Note: Flash Player version 9.0.115.0 and later allows the. (period) character in the id and name attributes.

Programmatically using this class to open pop-up Windows in Flash Player 10 and later running in the browser may not succeed. Different browsers (and browser configurations) may block pop-ups at any time; There is no guarantee that any pop-ups will be displayed. However, to be as successful as possible, use this class to open a pop-up window only in code that is executed as a direct result of a user action (for example, in an event handler for a mouse click or key event).

Using ActionScript, you can do the following on an HTML page:

Call any JavaScript function.
Pass any number of arguments with any name.
Pass various data types (Boolean, Number, String, and so on).
Receive the return value from the JavaScript function.
By using JavaScript on HTML pages, you can:

Note: in Adobe AIR, the ExternalInterface class is used to communicate between the JavaScript of an HTML page loaded in the HTMLLoader control and the ActionScript embedded in the SWF content of that HTML page.

Use this class in our MXML file. Call the function to get IP and pcname in js:

PcName = ExternalInterface. Call (" getClientPcName ");

IP =   Your externalinterface.call (" getClientIp ");  


You can try Alert to see if it's right. There is still a problem, add your machine as the server, then the IP obtained on the server will be: 127.0.0.1, handle it I believe you will have a way.


Related articles: