Web development is usually the flex and JS interaction, Unitywebplayer and JS interaction. They are more common to call each other.
/** * Flex calls JavaScript function * @params functionname:string javascript function name * @params ... params javascript function parameter * @return Returns the return content of the JavaScript function **/externalinterface.call (functionname:string, ... params);
/** * JavaScript calls Flex function * @params functionname:string JavaScript calls flex function name * @params closure:function the function that flex will call * @return void **/externalinterface.addcallback (functionname:string,closure:function);
JS calls the Unity Web content function
<script type= "Text/javascript" language= "javascript" ><!--//initializing the webplayervar u = new UnityObject2 (); U.initplugin (JQuery ("#unityPlayer") [0], "example.unity3d"); function saysomethingtounity () {u.getunity (). SendMessage ("MyObject", "MyFunction", "Hello from a web page!");} --></script>
You need a "MyObject" Gameobject object in Unity Web Player, and a script with a "MyFunction" function attached:
function MyFunction (param:string) { Debug.Log (param);}
the Unity Web Player invokes the JS function in the Web page:
Join the script in Unity to call Application.externalcall ("SayHello", "the game says Hello!");
In the Web page you need to define a call SayHello () function: <script type= "Text/javascript" language= "javascript" ><!--function SayHello ( ARG) { //show the Message alert (ARG);} --></script>
The above two modes of interaction are more commonly used, and a recent project has encountered a special application requirement. You need to check the pages of Unity Web Player into the Flex application framework and complete the flex interaction directly with unity Web player.
To complete this requirement, the following questions need to be addressed:
1, how to check the HTML page into the Flex container;
2, how to achieve the flex and Unity Web Player direct communication problems;
Question 1, through the collection of the current flex has an IFRAME plug-in, can be resolved.
steps: 1, Download the ready-made information in this link https://github.com/flex-users/flex-iframe/downloads I was under the latest Flex-iframe-1.5.1.zip decompression after the Flex-iframe-1.5.1\sources\library\flex-iframe\src\com\google\code\flexiframe This path can be found in two Acriptscript class files 2, To store iframe.as, iframeexternalcalls.as in a flex project, I'll copy it into a class file or reference bin\flex-iframe-1.5.swc3, a new Mxml application, add a red part of the code, Source fills the page to be displayed <?xml version= "1.0" encoding= "Utf-8"? ><s:application xmlns:fx= "http://ns.adobe.com/mxml/ "Xmlns:flexiframe=" http://code.google.com/p/flex-iframe/"xmlns:s=" Library://ns.adobe.com/flex/spark " xmlns:mx= "Library://ns.adobe.com/flex/mx" minwidth= "955" minheight= "All" Xmlns:iframe= "class.*" > <fx:Declara Tions> <!--Place non-visual elements (such as services, value objects) here-</fx:Declarations> <iframe:iframe id= "iframe" source= "http/ www.baidu.com/"width=" 100% "height=" 100% "/></S:APPLICATION>
Issue 2, resolve flex to communicate directly with Unity Web player.
Unity Web Player calls the Flex function, the key is the red callout on the graph, it is very good to understand that the IFRAME is checked into the flex HTML, through the iframe script found in the Swfcontent object can be implemented to call the function in Flex, Enable communication with Flex.
Flex Integrated Iframe,iframe integrated Unitywebplayer direct communication call solution