Develop an Encryption App Using Flash and MDM Zinc

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 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.

public class Main extends Sprite
{

Step 7: Variables

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

var tween:Tween; //A tween object to animate
var textView:TextView; //The TextView object, this is an instance of the TextView MovieClip
var back:BackButton; //An instance of the BackButton we created before

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.

public class Main extends MovieClip
{

Step 9: Constructor Function

This is the main function.

public function Main():void
{
mdm.Application.init(this, onInit);//Initialises {mdm}Script™. This is only required for applications programmed in ActionScript 3.
}

Step 10: Init Function

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

private function onInit():void
{
addButtonListeners();//Adds the listeners to the main four buttons
}

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 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.