Posts tonen met het label javascript. Alle posts tonen
Posts tonen met het label javascript. Alle posts tonen

zondag 20 december 2015

HaXe / Stencyl : Javascript

== Javascript from haxe ==

code-block:

flash.external.ExternalInterface.call(“o3p_write(\”this is the text to store\”)”);


flash.html

<<html>
<head>
<script type="text/javascript">
   function hallo(){
   alert('hallo from swf');
   }
   function o3p_write(v){
   alert('Hi What is variable v : '+v)
   }
   
</script>
</head>
<center>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="480" HEIGHT="320" id="TileAPI" ALIGN="">
<PARAM NAME=movie VALUE="TileAPI.swf"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#333399> <EMBED src="TileAPI.swf" quality=high bgcolor=#333399 WIDTH="480" HEIGHT="320" NAME="TileAPI" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED> </OBJECT>
</center>
</html>

Another:

ExternalInterface.call return values

To run javascript code inside a flash game you can use externalinterface.call.
The returnvalue is’nt always working.
This worked in Stencyl:



var theResult:String="";
#if flash
          theResult=ExternalInterface.call("doit_return");
trace("The result is: "+theResult);
#end


Javascript function:
function doit_return(){
   return "abcdef";

}

zaterdag 19 december 2015

Calling Java from Javascript and Calling Javascript from Java



This little sample shows that we can call javascript doAlert from Java.
Also we show that calling the function display will be received in Java with
data from Javascript.


applet.java

import java.applet.*;
import java.net.*;

public class applet extends Applet{
public void init(){
Display("start of java");
}
public void Display(String txt){
try{
getAppletContext().showDocument(new URL("javascript:doAlert(\""+txt+"\")"));
}catch(Exception e){}
}
}

index.html


<HTML>
<SCRIPT>
function doAlert(s) {
   alert(s);
}
</SCRIPT>
<APPLET CODE="applet.class" NAME="applet"  MAYSCRIPT >
</APPLET>
<INPUT type="button" value="Java.Display" onClick="document.applet.Display('hi')">
</HTML>