To do 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 parameters * @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>
There needs to be a "MyObject" Gameobject object in Unity Web Player, and a script with a "MyFunction" function is attached:
function MyFunction (param:string) { Debug.Log (param);}
the Unity Web Player invokes the JS function in the Web page:
Add the script in unity to call Application.externalcall ("SayHello", "the game says Hello!");
In a Web page you need to define a function called SayHello (): <script type= "Text/javascript" language= "javascript" ><!--function SayHello ( ARG) { //show the Message alert (ARG);} --></script>
The above two interaction methods are more frequently used, a recent project has encountered a special application requirements. You need to check the page of Unity Web Player into the Flex application framework. and finished with the direct interaction of flex with Unity Web Player.
In order to complete this need to solve such problems as the following:
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.
step: 1, download the ready-made data in this link https://github.com/flex-users/flex-iframe/downloads I'm under the latest After Flex-iframe-1.5.1.zip decompression, 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, iframe.as, iframeexternalcalls.as stored in the Flex project. I copy it to the class file or reference bin\flex-iframe-1.5.swc3, the new Mxml application, and add the 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/2009" 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=" 9 "Minheight=" xmlns:iframe= "class.*" > <fx:Declarations> <!--Place non-visual elements (such as services, value objects) here--</fx:d eclarations> <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, in fact, 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 resolution