PayPal and AS3

I need to create “buy now” button in Flash and code it with AS3, so that it connects to a clients PayPal store. This is the code I’m using, but it doesn’t connect to their “shopping cart” it only connects directly to the main PayPal Home Page.

Any ideas on what I may be doing wrong and why the variables are not being recognized by PayPal would be most appreciated. Thank you very much.

this.paypal_btn.addEventListener(MouseEvent.CLICK, paypalLink);

function paypalLink (event:MouseEvent):void {

var paypalURL:URLRequest = new URLRequest(“”);

var paypal:URLVariables = new URLVariables();
paypal.cmd = ‘_cart’;
paypal.upload = ‘1’; = ‘’;
paypal.currency_code = ‘USD’;
paypal.amount = ‘12.99’;
paypal.item_name = ‘Their CD’;
paypal.no_note = ‘1’;

paypalURL.method = URLRequestMethod.POST; = paypal;

navigateToURL(paypalURL, “_blank”);


Have you tried creating your button code in paypal account?

what about creating the button in paypal and sending the info form the flash button to paypal.

Thanks for the replies. Turns out it was a case of double quotes vs single quotes. I was using single quotes for my variables. I don’t think it should make any difference, but with PayPal it does. Once I switched the variables to use double quotes it worked fine.


I’m new here and have been using AS3 for about a month (so I’m still a relative newbie to the AS3 world). I came across this post, as I’m in the process of moving paypal AS2 buttons to AS3. I have my first paypal button working in AS3, but the issue is coming in with the right way to code it out for the multiple buttons that appear on the frame.

In AS2 this was pretty straight forward, but in AS3 I’m having issues (due to the fact I’m new). If one of you could help that would be fantastic!

Here’s my code (from a tutorial – re-posting with tutor’s comments in case it helps you or someone else):

// Button Click Function like any other you would code in AS3
function donateNowDown(event:MouseEvent):void {

// Here you define the URL address you want to connect to
var url:String = “”;

// Define the URLRequest object and use url string from above
var payPal:URLRequest = new URLRequest(url);

// Set up URL variables object and start claiming all variable names and value pairs
// See paypal documentation for adjustments in these name value pairs as you need them
var variables:URLVariables = new URLVariables();
variables.cmd = “_s-xclick”;
variables.hosted_button_id = “insert your ID”; = “insert your paypal email”; // your merchant email at paypal
variables.item_name = “insert product name”; // Name of the product
variables.item_number = “insert item number”; // Leave blank if item has no number
variables.amount = “10.00”; // Set the price here
variables.no_shipping = “2”;
variables.no_note = “1”;
variables.currency_code = “USD”; = “US”;
// Place all the variables above into a data packet of the URLRequest var = variables;
// Set the method to be ‘POST’ for sending the variables to paypal server
payPal.method = URLRequestMethod.POST;

// And finally we navigate to the PayPal Gateway Page for your biz
navigateToURL(payPal, “_self”); // Same window method, no popup(recommended)

// Button Listener, set to run the function above when user clicks
donateNow_btn.addEventListener(MouseEvent.CLICK, donateNowDown);

YEAH!!! I say finally but this was not as easy I thought it’d be-- the “newy-ness” of it all was preventing me from seeing what was right in front of my eyes.

For anyone else having issues in this area, I realized that I just needed to copy and paste the function code with variables (and then, replace the button name and the applicable paypal variables with the new information for the button).

So in my case, I have 6 buttons.

I created 6 functions, each with a different btn name and for each changed the: variable id, variable item amount and the variable item number (you may have more or less).

Then, I created 6 Event Listeners, each on its on line with its own Btn name. Made sure I had each button in the “down” state. I tested it and it worked.

I am by no means an expert, and perhaps one of the experts or advanced developer/designers on here can give even more insight or provide a better way – posting the solution I discovered because perhaps it can help someone else save hours of searching for this same kind of functionality.

Just when you think the scream will pierce the air and ears of those who created Flash, a ray of sunlight bursts through!!!