Quick Guide: Creating Paypal Buttons with ActionScript 3.0

In this tutorial we’ll quickly create two different Paypal buttons: "Buy Now" and "Donate". All we’ll need is a Paypal Business Account to generate some code for us.

Final Result Preview

Let’s take a look at the final result we will be working towards:

Step 1 – Document Setup

Launch Flash and create a new ActionScript 3.0 document (File > New…). Set the stage size to 600 px width and 400px height with 30 fps. I’ve chosen black (#000000) for the background.

””

Step 2 – Create the Flash Buttons

Create two layers. Name the first layer "Buttons" and the second "Actions". On the "Buttons" layer, create two buttons; one with the text "Donate a Cup of Coffee" and the other with the text "Buy Donuts". Select the Donate button, then go to properties and assign an instance name of "btDonate". Lastly, assign an instance name of "btBuynow " for the Buy Now button.

Step 3 – Login to Paypal.com

Go to www.paypal.com and login as shown in the image below.

””

Step 4 – Customizing the Donate Button

Go to "Merchant Services" and click on the option "Donations" located in the "Key Features" panel.

Firstly, we’ll customize our button "Donate". Enter a name for the "Service" and then a "Donation ID". Now choose the currency and select "Donors contribute a fixed amount" (just type an amount). The final task for this step is to select "Plain text e-mail address".

Now we move to step 2 and check "Save button at Paypal"; this is a new feature and it’s very useful.

For step 3 we’ll customize the advanced features. Select "No" for the first two options and if you wish, you can enter the url for "cancellation" and "successful" pages.

Click on "Create button" and the next screen will show you the HTML code.

””/

Step 5 – Customizing the Buy Now Button   

To customize the other button, again go to "Merchant Services". This time, click on the "Buy Now" option located in the "Key Features" panel.

Within the first step choose "Products" from the combo box, select "Accept payments for" and "No, create a Buy Now button". Then enter a "Name" and "ID" for your service or product. Set the "price", "currency " and specify the "shipping" amount.

Then, go to step 2 and check "Save button at Paypal".

Lastly, within step 3 select "No" for the first two options and again, if you wish, you can type the url for "cancellation" and "successful" pages.

Click on "Create button".

””/

Step 6 – Copy the HTML Code 

Now the two buttons have been created, go to your "Profile" and click on "My Saved Buttons" which you’ll find in the "Selling Preferences" panel. Click on the "Action" drop down menu and select "View code". Copy the code, go back to Flash and paste the clipboard contents into your "Actions" layer. Repeat these steps for the other button and comment it all as HTML code.

””/

Step 7 – Define "EventListener"

Copy the following lines of code into your "Actions" layer:

btDonate.addEventListener(MouseEvent.CLICK, donate);
btBuynow.addEventListener(MouseEvent.CLICK, buynow);

Step 8 – Define the "buynow" and "donate" Functions

Copy the following lines of code into your "Actions" layer:

function donate (event:MouseEvent):void
  {
var url:String = "https://www.paypal.com/cgi-bin/webscr"; //<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
var request:URLRequest = new URLRequest(url);
var paypal_donate:URLVariables = new URLVariables();
paypal_donate.cmd="_s-xclick"; //<input type="hidden" name="cmd" value="_s-xclick">
paypal_donate.hosted_button_id="4893693"; //<input type="hidden" name="hosted_button_id" value="4893693">
request.data = paypal_donate;
navigateToURL(request);
trace(paypal_donate)
}

function buynow (event:MouseEvent):void
  {
  var url:String = "https://www.paypal.com/cgi-bin/webscr"; //<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
  var request:URLRequest = new URLRequest(url);
  var paypal_buynow:URLVariables = new URLVariables();
  paypal_buynow.cmd="_s-xclick"; //<input type="hidden" name="cmd" value="_s-xclick">
  paypal_buynow.hosted_button_id="4901978"; //<input type="hidden" name="hosted_button_id" value="4901978">
  request.data = paypal_buynow;
  navigateToURL(request);
  trace(paypal_buynow)
  }

Conclusion

Test your movie to check the link between flash and paypal.com. If you wish, you can modify the paypal buttons (taxes, tracking, inventory, donation amount, etc), have fun playing with it! I hope you enjoyed this quick guide.

Related Posts

Add Comment

Discussion 45 Comments

  1. zeroone says:

    Greate tutorials

  2. nightwork says:

    Awesome tutorial! Was looking for these!
    Thanks!

  3. Franky says:

    Nice tut. I guess this would also work for opening any external page!

    Nice.

  4. Good tutorial. Simple and straight forward.

  5. joell lapitan says:

    nice tut.. this will be very helpful..

  6. James says:

    Awesome! very well explained

  7. shampi says:

    Awesome ! Really effective

  8. lawrence77 says:

    nice tut thanks! ;)

  9. tirtha says:

    it’s so fantastic please sent me this like any tuts at pakhrin299@hotmail.com

  10. Luis María says:

    Me da mucho orgullo saber que un compatriota mexicano escribe en este tipo de sitios con gran calidad. Te felicito. Vi tu sitio y me gusto mucho la gráfica además de su sencillez.

    yo soy del estado de México y llevo diseñando en flash como tres años, mi fuerte más bien es el diseño y animación, me cuesta la programación.

    Yo también hago tutos pero con tópicos más comunes.

    Te dejo Saludos!!!

    • Gracias María, checa mi nuevo blog de labs tengo 2 tuts por publicar, quedate pendiente. Saludos desde Cancun. Sigueme en twitter @_dariux. Saludos.

      Thanks Maria, you can check my new blog dg labs, I have 2 tuts for soon publish, I will wait your visit. Best regards!

  11. qana6r-des.com says:

    wooow
    gooog

  12. swarup podar says:

    very nice tut…

  13. atanism says:

    no add to shopping cart button?

  14. teneb says:

    Is it possible to let the user input any other amount instead of the predefined values?

  15. brendan says:

    thanks

  16. brendan says:

    how would a view cart work though?

  17. Lisa Mercedes says:

    Nice tutorial. It would be grand if you taught us how to also create “View Cart” and “Checkout” buttons to complete the tutorial.

    x lisa x

  18. sergio says:

    Awsome tutorial, been looking for something like this!!

  19. angie says:

    this is great! I am stuck trying to incorporate the flash combobox component so I can have choices for sizes. Any pointers?

    Thanks!

  20. Eric says:

    @atanism: shopping cart? like if you wanted to buy a dozen donuts? haha

    -Eric

  21. how would i create a flash action script 3.0 button with multiple options, that communicates with paypal, to purchase products, I’ve created individual buttons in flash (for Now) using AC 2.0 see (i.e) on my site…
    gogreekstore.com

  22. Dulisha says:

    This is Good Man,In moment need me Flash Button to use for Pay Pal.

  23. Lisa Mercedes says:

    View cart code for ActionScript 3.0 is soooooooo hard to find…why?

  24. alex says:

    Is there a way to have it so that instead of donating a cup of coffee, it goes to a Text input box (numbers only)

    Where the user enters like 5.00 and that is what they are donating?

    Or 7.00 and thats their donation?

    Is that possible?

    Thanks

  25. david says:

    hey guys this is the tuts ive been after for ages does any one know how to make a view cart button :) i keep getting ioerror

  26. david says:

    great tut could anyone help me create a view cart the same way i keep gettng a error

  27. Jen says:

    Great tutorial Dario! Is it possible to create an “Add to Cart” button using the method shown in this tutorial?

  28. Michael Webb says:

    Can this be modified to work with actionscripting 2.0 ??

  29. lean ray says:

    How can I make a button like this using flash actionscript 2 & 1?

  30. Faraz says:

    Nice Script very simple and easy. Thanks Faraz

  31. Osirus says:

    This is an excellent start for me … thank you. I am working to build a shopping cart using Flash CS3 and would like to know if it is possible to add combo boxes containing color/size options and passed onto paypal for purchase using Actionscript 3?

  32. Kamil says:

    Could you please post it in ActionScript 2.0?
    I just need the script in AS2.0 for “buy now” button.
    I’d appreciate any help,

  33. Rob says:

    Not totally related, but if you want to create over a hundred buttons, it is obviously quite painful to do it through button manager, is there any other way to create paypal buttons. I have a mysql database in the background with all the info. I need, but I don’t have the hosted_button_id for each button unless I create the buttons online?
    Thanks for any help.

  34. Curi says:

    Thanks, was playing around with the coding for a bit myself ^^;

  35. Felicos says:

    Hey Dario,

    nice tutorial

    do you know the codes sending paypal your shopping & handling cost?
    I am thinking of making shopping fee based on the country selected by users.

  36. This is very awesome tutorial. However, I am a regular (type:personal) PayPal user and don’t have Business account. Can I still be to create a donation?

    In code, where you get your ID, I get encrypted text:
    <input type="hidden" name="encrypted" value="—–BEGIN PKCS7—–o;vn;eovna;onv;oaivnoeivnoiWHATEVERkjnadkjn —–END PKCS7—–;

    is it still doable?

  37. Steroids says:

    very nice can i use the same code for action Script 3.

    Please guide me

    Thanks
    Steroids

Add a Comment