Barcodes in Flash. Dynamically generating UPC barcodes using Actionscript.

Do you have a Shopping Cart program that uses Flash, and you need to display or print receipts with product Barcodes? One solution would be to have jpg files of all the barcodes and load them into Flash.

However, I will show you how to dynamically generate and display barcodes using Actionscript and a barcode font. This can save you a lot of storage space and bandwidth, and will generate vector barcodes, which will look smoother and print better than a jpg file.

Barcode Types

There are numerous types of barcodes in use these days, including UPC, ISBN, Code39, EAN, Code128, Codabar, and many others.

In the U.S., most barcodes on products for sale in stores are in UPC-A format, so we'll use that for our example here.

Understanding UPC Codes

UPC barcodes are a 12 digit code that include 4 general parts:

  • Number System - A single digit that generally defines a product type (Weighted items, Health/Drug, Non-Food, etc)
  • Manufacturer Code - A 5 digit string that is assigned to the manufacturer by the UCC, the governing body of UPC codes in the U.S.
  • Product Code - A 5 digit string that identifies that particular product from the manufacturer
  • Check Digit - A single checksum digit that allows a barcode scanner to test whether it properly read the barcode or not.

Later in this article, I'll show you how to generate (and thus test) a Check Bit for a UPC-A.

Barcode Fonts

To understand how to display a barcode on the screen, you must understand that there are different barcode characters that apply to different parts of the code.

In general, the code consists of:

  • a left side character
  • a left hand guard bar
  • 5 left side characters
  • a center guard character
  • 5 right side characters
  • a right hand guard bar
  • the check bit as a right side character

For our examples, the Font we are using has the left and right guard characters combined with the individual digits, so I'll call them Start Characters and Stop Characters

AttachmentSize
UPCA.zip20.88 KB