Using the OpenTok ActionScript library

The OpenTok ActionScript library to develop Flash applications that connect to OpenTok sessions.

You obtain the OpenTok ActionScript library SWC file at the Downloads page.

Versions of the SWC file

The OpenTok SWC file is updated periodically, as new features are added. It is not updated with each new version of OpenTok (if the release does not warrant changes to the OpenTok SWC file). The latest version of the SWC file is always posted at the Downloads page. When a feature requires a specific version of the SWC file (or a later version), the reference documentation for the API notes the required version.

Supported SWF versions

The OpenTok ActionScript library require that the client has Flash Player 11.1.0 or later.

Getting started using the OpenTok ActionScript library

Include the OpenTok SWC file in your application:

To include the opentok.swc file in Adobe Flash Builder (or Flex):

  1. Open your project.
  2. On the Properties menu, select Project.
  3. In the Properties dialog box, click ActionScript Build Path.
  4. Click the Add SWC button, browse to the opentok.swc file and select it. Then click the OK button. The SWC file is now included in the Package Explorer.

To include the opentok.swc file in Adobe Flash:

  1. Open your Flash project.
  2. On the File menu, select ActionScript settings.
  3. Click the Library path tab.
  4. Click the Browse to SWC file button (which looks like the Adobe Flash icon).
  5. Select the opentok.swc file you downloaded and then click the Open button.
  6. Click the OK button.

Using the MXMLC command-line compiler, add the path to the opentok.swc file to the -library-path compiler option, as in the following:

mxmlc -library-path+=c:/mylibraries/opentok.swc c:/myfiles/opentokTest/openTokTest.as3

Passing session IDs and tokens from the web server

In the SWF-embedding code of the HTML page, you can reference the generated session ID and token string as Flash variables (FlashVars). The following shows how to use PHP to pass values as Flash variables:

	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="770" height="500" id="MyApp">
	    <param name="movie" value="MyApp.swf">
	    <param name="quality" value="high">
	    <param name="bgcolor" value="#ffffff">
	    <param name=FlashVars value="apiKey=<?php print API_Config::API_KEY?>&sessionId=<?php print $sessionId; ?>'&token=<?php print urlencode($apiObj->generate_token($sessionId)); ?>">
	
	    <param name="allowScriptAccess" value="sameDomain">
	    <param name="allowFullScreen" value="true">
	    <!--[if !IE]>-->
	    <object type="application/x-shockwave-flash" data="MyApp.swf" width="770" height="500">
	        <param name="quality" value="high">
	        <param name="bgcolor" value="#ffffff">
	        <param name=FlashVars value="apiKey=<?php print API_Config::API_KEY?>&sessionId=<?php print $sessionId; ?>'&token=<?php print urlencode($apiObj->generate_token($sessionId)); ?>">
			<param name="allowScriptAccess" value="sameDomain">
	        <param name="allowFullScreen" value="true">
	        <!--<![endif]-->
	        <!--[if gte IE 6]>-->
	        <p>
	            Either scripts and active content are not permitted to run or Adobe Flash Player version 10.0.0 or greater is not installed.
	        </p><!--<![endif]-->
	        <a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player"></a> <!--[if !IE]>-->
	    </object> <!--<![endif]-->
	</object>
	

For this example, the ActionScript code in the SWF file would reference the sessionId, and token properties passed in as Flash variables:

var sessionId:String = LoaderInfo(this.root.loaderInfo).parameters.sessionId;
	var token:String = LoaderInfo(this.root.loaderInfo).parameters.token;
	token = unescape(token);

Use the ActionScript unescape() function to decode the token string. The example above encodes the token string when inserting it into the FlashVars value of the param tag. This encoding is necessary because the token string may contain characters, such as "=", that need to be encoded for use in the FlashVars string.

Developing Adobe AIR apps that use OpenTok

In an AIR app, you may choose to put the OpenTok Device Panel in its own native window. In Flex, you can use the PopUp manager class. In other apps, you can instantiate a new NativeWindow object. You can then put the Device Panel object (a sprite returned by calling the getDevicePanel() method of a DeviceManager object). For an example of using the Device Panel, see the Basic tutorial.

The OpenTok ActionScript Tutorials include a source code download zip file. This file includes a AIR version of the Hello World tutorial (in the AIRHelloWorld directory). This version includes a sample application descriptor file for AIR development. See the Hello World tutorial.

Note about Adobe AIR and mobile devices

Due to breaking changes in the latest version of Adobe AIR, we are no longer able to support AIR for mobile implementations of the OpenTok API. We apologize for any inconvenience this may cause, and are hard at work on other libraries for mobile platforms. To learn more, please email us at bizdev@tokbox.com.

IRC Live Chat

Have a quick question? Chat with TokBox Support on IRC. Join chat