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:
- Include the digital goods JavaScript library in the HTML page
game.html
, which also includes the Flash moviegame.swf
. -
Include the following ActionScript in the Flash movie
game.swf
to initialize the digital goods object:dg_button.addEventListener( MouseEvent.MOUSE_UP, 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 = ExternalInterface.call("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.
-
Create the Flash movie,
game.swf
, with the following code. The code assumes the button click ondg_button
initiates payment.// create local connection var conn:LocalConnection; conn = new LocalConnection(); // allow cross domain connection conn.allowDomain('*'); // identify this movie as the receiver (i.e. client) conn.client = this; dg_button.addEventListener( MouseEvent.MOUSE_UP, 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 = "window.open('"+payment_URL+"','win', 'height=550,width=400,toolbar=no,scrollbars=no');"; var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);"); navigateToURL(url, "_self"); //initiate listening on connection conn.connect('paymentConn'); }); function paymentComplete(responseText):void { //use responseText to do any customizations //close the LocalConnection conn.close(); }
- Specify another Flash movie,
return.swf
, as the return URL in the API call. - Use
FlashVars
orExternalInterface
inreturn.swf
to gather any required values from the API response. -
Use the
LocalConnection
from step 1 inreturn.swf
to communicate withgame.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);