Fran Verona
Fran Verona

Reputation: 5476

Layer system feature in my AS3 flash app

I'm developing a layer system feature for my Flash app (AS3 + Flash CS5). The goal is to create a system like Photoshop has where elements belong to a layer. These different layers could be hide or locked (to avoid element moves).

I want to create a MovieClip (with basic class called 'Layer') and associate it others MovieClip.

Something like this:

example

This should be compossed by more MovieClips: eye (to control layer visibility), name (to allow dynamic name changes) and lock (to lock elements inside the layer).

How can I reference these differents MovieClips inside my basic class 'Layer'? Or how can I consider my design to allow this behaviour?

Is there any different or better way to do this?

Thanks!

Upvotes: 0

Views: 343

Answers (1)

Petre Popescu
Petre Popescu

Reputation: 2002

The only way to optimally make this that I can think of right now is to have two classes. A "Layer" class that has all the "drawings". this can be only a MovieClip (or a class that extends MovieClip). Next you have the "LayerInfo" that has the visual aspect that you show in the image. This class also extends MovieClip, but has a variable, let's call it visualLayer, that is a reference to the Layer on the stage.

So basically, when you press the "New Layer" button, you crate two objects: The drawing Layer, and the LayerInfo object. next, if can simply have a public method hideLayer for turning the layer on and of. It will be something like this:

public function togleLayerVisibility():void{
    this.visualLayer.visible = !this.visualLayer.visible;
    //optional, you can make the eye different as well
    //this.eye.togleVisual();
}

In the same way you can do other stuff on the VisualLayer.

Upvotes: 1

Related Questions