Provides methods for the interaction between the current application and the external interface.
public class ExternalInterface: Object
ObjectExternalInterface
// This sample shows how to implement the ExternalInterface class.
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
public class MyForm: System.Windows.Forms.Form
{
private TextBox tb;
private Button button;
private TextBox label;
public MyForm()
{
InitializeComponent();
}
void display_msg( string msg )
{
Debug.WriteLine(msg
);}
private void InitializeComponent()
{
tb= new TextBox();
tb.Location = new Point(10, 10);
button= new Button();
button.Location = new Point(10+200+10, 10);
button.Text = "Send to Javascript";
button.Click += new EventHandler(send_to_js);
label= new TextBox();
label.Location = new Point(10, 50);
label.Size = new Size(300, 200);
label.ScrollBars= ScrollBars.Vertical;
label.Text = "This SWF movie should be launched through extitf.html\n\n";
display_msg( "External Interface Available : "+ExternalInterface.IsAvailable+"\n" );
bool outcome= ExternalInterface.AddHandler( "my_swf_method",
new ExternalInterfaceHandler(my_swf_method) );
Debug.Assert( outcome, "ExternalInterface.AddHandler() failed" );
}
object my_swf_method( object[] args )
{
string s= "[";
for( int i= 0; i < args.Length; ++i )
{
if( i > 0 )
s += ", ";
object arg= args[i];
if( arg == null )
{
s += "<null>";
continue;
}
if( arg is string )
{
s += "'" + arg.ToString() + "'";
continue;
}
}
s += "]";
string msg= "my_swf_method() invoked from javascript with arguments: "+s;
display_msg(msg);
return "<returned_data_from_swf>";
}
void send_to_js( object sender, EventArgs e )
{
string method= "my_js_method";
object res= ExternalInterface.Invoke( method, tb.Text, "abcde", 12345 );
string msg= method + "() returned : "+((res==null) ? "<null>" : res.ToString());
display_msg(msg);
}
static void Main()
{
Application.Run( new MyForm() );
}
}
/*
<HTML>>
<BODY>
<!-- saved from url=(0013)about:internet -->
<object
id="swfmovie"
width="400"
height="300"
align="CENTER"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000">
<param name="movie" value="bin/Debug/extitf.swf"/>
<param name="quality" value="high"/>
<param name="scale" value="noScale"/>
<param name="FlashVars" value=""/>
<param name="SeamlessTabbing" value="false"/>
<embed
src="bin/Debug/extitf.swf"
name="swfmovie"
width="400"
height="300"
quality="high"
scale="noScale"
FlashVars=""
SeamlessTabbing="false"
swliveconnect="true"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
type="application/x-shockwave-flash">
</embed>
</object>
<br>
<script>
function getFlashObject( name )
{
if( window.document[name] )
return window.document[name];
if( navigator.appName.indexOf("Microsoft Internet") == -1 )
{
if( document.embeds && document.embeds[name] )
return document.embeds[name];
return null;
}
return document.getElementById(name);
}
function invoke_swf()
{
fo= getFlashObject("swfmovie");
if( fo == null )
{
alert("Cannot find Flash html object");
return;
}
res= fo.my_swf_method("first","second",3.14,123,true,null);
alert( "Javascript Alert: my_swf_method() returned: "+res );
}
// invoked from SWF movie
function my_js_method( some_text, arg2, arg3 )
{
alert("Javascript Alert: Message Received from SWF:\n\n"+some_text+"\n"+arg2+"\n"+arg3);
return "<returned_data_from_js>";
}
</script>
<br>
<A href="javascript:invoke_swf()">Click to invoke my_swf_method() in the SWF application</A>
</BODY>
</HTML>
*/
Namespace System Flash Library corlib.scl Flash Library Version 2.0.0.2466 Silverlight Library System.Windows.Forms.dll
| © 2003-2007 NETiKA Technologies. All rights reserved. |