LATEST BLOG ENTRY

Drawing shortcut for MovieClip.graphics

March 1, 2010

Thought I’d share this little shortcut that I hadn’t really come across before, which definitely helps to keep your code that little cleaner when working with MovieClip.graphics in Flash.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
this.grapics.lineStyle(1, 0x00000);
this.graphics.moveTo(10, 10);
this.graphics.lineTo(10, 20);
this.graphics.lineTo(20, 20);
this.graphics.lineTo(20, 10);
this.graphics.lineTo(10, 10);
                   
this.graphics.beginFill(0xFF0000);
this.graphics.drawCircle(40, 40, 20);
this.graphics.endFill();
                   
this.graphics.beginFill(0x00FF00);
this.graphics.drawRoundRect(40, 0, 40, 20, 2, 2);
this.graphics.endFill();

Can also be written:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
with (this.graphics) {
    lineStyle(1, 0x00000);
    moveTo(10, 10);
    lineTo(10, 20);
    lineTo(20, 20);
    lineTo(20, 10);
    lineTo(10, 10);
   
    beginFill(0xFF0000);
    drawCircle(40, 40, 20);
    endFill();
   
    beginFill(0x00FF00);
    drawRoundRect(40, 0, 40, 20, 2, 2);
    endFill();
}

Pretty simple, and surprised I hadn’t seen (or thought of) it before.

Replacing Events with AS3Signals

February 7, 2010

I’ve been playing with AS3Signals lately, and think I will be replacing flash events with it on all future projects.

It’s so simple!

So what is AS3Signals?

AS3Signals is a lightweight replacement for Flash Events written by Robert Penner.

AS3Signals aims to reduces the amount of traditional ‘boiler plate’ code required to receive and dispatch messages in Flash.

Why use AS3Signals?

Writing custom events tends to be a bit of a tedious chore on most projects, and I know many developers approach custom Events in different ways.

Some choose to create a single flexible Event with a loosely typed payload (ie. data:Object), while others like myself, like to strongly type events with value objects wherever I can (resulting in many custom event classes per project).

AS3Signals practically does away with the need for custom event classes altogether, as you now simply append any number of parameters to your signal.

The time saved not having to write all of these custom events alone is reason enough to jump into AS3Signals.
Read more…

PREVIOUS ENTRIES

New Years Resolutions

February 7, 2010