Methods For Integrating Digital Goods Into Flash

Important: This integration method is deprecated as of January 1, 2017. PayPal continues to support existing merchants using this method, but please be advised new features and enhancements will not be applied to these integrations. For new integrations, see the PayPal Checkout Integration Guide.

You can integrate digital goods into a Flash file.

Integrating with Flash

To integrate digital goods with Flash:

  1. Include the digital goods JavaScript library in the HTML page game.html, which also includes the Flash movie game.swf.
  2. Include the following ActionScript in the Flash movie game.swf to initialize the digital goods object:

    function(evt:MouseEvent):void {
    var payment_URL:String = "<Merchant URL to initiate API call>";
    // use ExternalInterface to call the JavaScript method dg.startFlow
    var result:uint ="dg.startFlow",payment_URL);
    function paymentComplete(responseText):void {
    // use responseText to do any customizations
    // register the callback method so it can be called via JavaScript
    ExternalInterface.addCallback("paymentCompleteExt", paymentComplete);

Integrating with Flash for third-party merchants

This example shows third-party merchants how to integrate digital goods with Flash.

In the following example, use ActionScript 3.0's LocalConnection in the Flash movie, game.swf, to respond to the payment.

  1. Create the Flash movie, game.swf, with the following code. The code assumes the button click on dg_button initiates payment.

    // create local connection
    var conn:LocalConnection;
    conn = new LocalConnection();
    // allow cross domain connection
    // identify this movie as the receiver (i.e. client)
    conn.client = this;
    function(evt:MouseEvent):void {
    // following URL will begin the DG API call
    var payment_URL:String =
    "<Merchant URL to initiate API call>";
    // following JS opens a new window to the appropriate size
    // for DG checkout
    var jscommand:String =  "'"+payment_URL+"','win',
    var url:URLRequest = new URLRequest("javascript:" +
    jscommand + "
    navigateToURL(url, "_self");
    //initiate listening on connection
    function paymentComplete(responseText):void {
    //use responseText to do any customizations
    //close the LocalConnection
  2. Specify another Flash movie, return.swf, as the return URL in the API call.
  3. Use FlashVars or ExternalInterface in return.swf to gather any required values from the API response.
  4. Use the LocalConnection from step 1 in return.swf to communicate with game.swf, for example:

    var sendingLC:LocalConnection = new LocalConnection();
    // do anything required to get API response parameters into
    // the "response" variable
    // connect to game.swf and call paymentComplete
    sendingLC.send('paymentConn', 'paymentComplete', response);