1. Code
  2. ActionScript

Develop an Encryption App Using Flash and MDM Zinc

Read Time:6 minsLanguages:

Encryption is the process of transforming information using an algorithm to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.

Using Multidmedia Zinc we'll create an encryption application in ActionScript 3, capable of encrypting text and files with a user specified key.

Step 1: Brief Overview

Using the mdm.Encryption class and its methods, we will make use of a simple interface to obtain the file, text and key to encrypt.

Step 2: Starting

Open Flash and create a new Flash File (ActionScript 3).

Set the stage size to 500x300 px.

Step 3: Interface

A simple interface will work very well in this application, so i'm not going to detail its creation.

Four buttons are present in the start screen, a Texfield and an icon is used to display its function. There is also another Texfield in the bottom of the stage that will display a message when the encryption/decryption is completed. You can see the instance names in the image.

This is the second view used in the movie. It's a MovieClip named "TextView" wich will be called from ActionScript (remember to check the box), a big TextField named "encryptText" and the other one named "encryptKey". In the Encrypt File sections, the "encryptText" field MUST have a full path, you can't implement a browsing method to get a full path for security reasons.

There are also two buttons, "encryptionButton", and a button that will be called with ActionScript to go back to the start screen, it's called "BackButton" remember to check the "Export for ActionScript" when converting to MovieClip.

As you can see, the interface is very simple. Remember that if you have doubts on the instance names you can check the source.

Step 4: The Code

We'll use a single class in this application.

Create a new ActionScript file and save it as "".

Step 5: Necessary Classes

Let's first import the classes we'll need.

Step 6: Declaring and Extending the Class

The extends keyword defines a class that is a subclass of another class. The subclass inherits all the methods, properties and functions, that way we can use them in our class.

Step 7: Variables

These are the variables we'll use, explained in the comments.

Step 8: Extending the Class

We're going to use MovieClip specific methods and properties so we extend using the MovieClip Class. Extending using the Sprite Class won't work.

Step 9: Constructor Function

This is the main function.

Step 10: Init Function

This function is executed when the mdm Script starts. It just calls a function to add some button listeners.

Step 11: Add Button Listeners

This is the function that adds the listeners.

Step 12: Remove Button Listeners

The listeners will be removed when one of the buttons is clicked.

Step 13: Button Animation

An animation will move the buttons from the stage to hide them.

Step 14: File Encryption Handlers

These functions call the File encryption/decryption depending on the button clicked.

Step 15: File Encryption/Decryption

These functions use the mdm.Encrypt class to Encrypt/Decrypt a file, obtained by writing a full path in the big TextField, and writing a key in the small one.

Editor's note: I'm afraid the ActionScript in this step is causing our syntax highlighter to trip Firefox up (this sometimes happens and I've no idea why). For now, it's best you download it to have a look. Sorry for the inconvenience.

Step 16: Text Encryption Handlers

These functions call the Text encryption/decryption depending on the button clicked.

Step 17: Text Encryption

These functions use the mdm.Encrypt class to Encrypt/Decrypt a String, obtained by writing text in the big TextField, and writing a key in the small one.

Step 18: Text View

The TextView is the view that appears when one of the four main buttons are clicked, here's the code that brings it up.

Step 19: Back Button

The Back button shows up when the TextView is active. When pressed, it returns the buttons to the screen and removes the TextView and itself. It also clears the "message" TextField.

Step 20: Document Class

Go back to the Fla and in the Properties Panel, Class textfield add "Main". This will link the Main class as the Document Class.

Step 21: Zinc

Now, testing your new application will result in a series of erros resulting from the use of the MDM Classes. To fix that and make your Encryption work we have to get Multidmedia Zinc.

Zinc is a Flash Application Development Software that extends the Flash Movie's functionality by using {mdm}Script, a programming language similar to ActionScript, you can download a free trial version from its website.

Step 22: Zinc Component

After you download Zinc Builder you have to link their compiled component to Flash in order to interpret the mdm script and remove the error warnings.

Go to Flash > Preferences > (Category) ActionScript > ActionScript 3.0 Settings and click the swc icon to add the component.

Test your movie to create a swf with no errors and open Zinc.

Step 23: Building

Create a new Project (Cmd + N) and browse for your swf file.

Use the left and right panels to customize your application.

Then go to the Extensions tab, and mark the mdm_encryption combobox.

Finally, go to Project > Build Project and click build to compile your application.


Test your new Encryption software, and remember to explore the Zinc {mdm}Script!

Thanks for reading :)

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.