GOA - System.ExternalInterface

ExternalInterface Class


Provides methods for the interaction between the current application and the external interface.

Definition

public class ExternalInterface: Object

Members Table

MethodDescription
AddHandlerAdds the handler to an external interface with the specified method.
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object)
GetTypeGets the Type of the current instance. (Inherited from Object)
InvokeInvokes the specified method of an external interface.
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
RemoveHandlerOverloaded. Removes the handler of external interface with the specified method.
ToStringReturns a String that represents the current Object. (Inherited from Object)
PropertyDescription
IsAvailableGets a value indicating whether the external interface is available.

Inheritance Hierarchy

Object
ExternalInterface

Examples

 // 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 )

      {

            label.Text += msg + "\n";

            Debug.WriteLine(msg);

      }

      private void InitializeComponent()

      {

            this.SuspendLayout();

            tb= new TextBox();

            tb.Location = new Point(10, 10);

            tb.Width= 200;

            tb.Text = "Some Text";

            button= new Button();

            button.Location = new Point(10+200+10, 10);

            button.Text = "Send to Javascript";

            button.Width = 120;

            button.Click += new EventHandler(send_to_js);

            label= new TextBox();

            label.Location = new Point(10, 50);

            label.Size = new Size(300, 200);

            label.Multiline= true;

            label.ReadOnly= true;

            label.ScrollBars= ScrollBars.Vertical;

            label.Text = "This SWF movie should be launched through extitf.html\n\n";

            this.Controls.Add(tb);

            this.Controls.Add(button);

            this.Controls.Add(label);

            this.ResumeLayout(false);

            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 += args[i].ToString();

            }

 

            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>

*/

Class Information

NamespaceSystem
Flash Librarycorlib.scl
Flash Library Version2.0.0.2466
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.