1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Deconstructing the Paint Application IIX: User Layers, Clear Layer

By

1 of 5

Setting Up Layer Buttons
Deconstructing the Paint Application IIX: User Layers, Clear Layer
We’ve worked out the basics of how the drawing is done in the Flash Oekaki/Paint Application, but what about where that drawing’s done? The application is set up a bit more complexly than a single canvas; instead it has two layers, and you can draw on either layer without affecting the one above or below. We’re going to take a look at how those layers are set up.

The first thing we need to do for this is set up the layer buttons. At the bottom of my application’s control panel I have two buttons, one marked 0, the other marked 1; the application opens with layer 0 active and the layer 0 button highlighted. Clicking the layer 1 button would make layer 0 inactive and make layer 1 active; clicking it a second time even while layer 1 was active would make layer 1 inactive and make layer 0 active. The same works in reverse for layer 0.

How is this done? Instead of testing strictly for true/false values of variables representing the layer activity, instead simply add the following code to each button:

on (release){ 
_root.layerzero=!_root.layerzero; 
_root.layerone=!_root.layerone; 
}

Assuming that one layer starts off true and the other false (something we’ll define in the next step), this code will always cause the two to switch when either button is clicked, because all it does is take the existing value of each one and convert it to its opposite.

I’ve only created two layers on mine, but you could create as many as you wished.

©2014 About.com. All rights reserved.