Lemieux Design

Flash | Interactive | Web | Graphics | Brand | Video

24 hour – 12 hour conversion in AS3

Posted on: September 23rd, 2010 by alemieux 3 Comments

Getting the current time is easy in AS3 with the Date() class, however the default clock is the 24 hour (military) clock.

Start by creating a new Date object:

var myDate:Date = new Date();

The Date class allows you to get to the month, day, hours, minutes, seconds and other Date-based information. If we try to trace out the time like this:

trace(myDate.hours + “:” + myDate.minutes + “:” + myDate.seconds);

We’ll get 16 for the hours at 4 pm. The solution is really simple. Just subtract 12 from the hours to get the 12 hour hour.

trace(myDate.hours – 12 + “:” + myDate.minutes + “:” + myDate.seconds);


Time Machine to the Rescue

Posted on: July 30th, 2010 by alemieux

So there’s a lot of negative talk out there about Time Machine and yes, I can agree to most of it. Time Machine, OS X’s built-in backup program, is a little slim on the configuration options and fills up a hard drive pretty quickly with backups. There doesn’t seem to be a lot of flexibility with the program. (If you know of other Mac-based backup solutions, please list them here.)

In the past few weeks however, Time Machine has actually saved me some trouble. A file that I was working with became corrupted or unusable. Then I remembered Time Machine and went into it. Every time I do, my kids’ jaws drop as the desktop changes and the spaceship like interface takes over. I went back in history, grabbed an older version of the file and restored it to the desktop. I was then able to open the file and modify it. Of course, I had lost some development time, but being able to resurrect a file like that is really priceless.

So as much as there is negative talk out there, Time Machine really proved useful for me.

Building a Flash Class

Posted on: April 22nd, 2010 by alemieux

Making the transition from procedural (inline) ActionScript to Class-based scripting has been – admittedly – pretty challenging for me. Understanding what’s public and what’s private, how to structure your code, what are the necessary imports, getting class paths right, there’s just so much to think about that normally, with procedural scripting, you don’t have to.

For example, importing classes is a complete nightmare of a task. What I discovered of late is that anything that is in the flash class library (ex. flash.display.MovieClip) is already available to you in the Flash IDE. Anything in the fl library (ex. fl.transitions.Tween) isn’t, so those need to be imported. Flash CS4 doesn’t automatically add the class import statements, but I hear that Flash Builder does and maybe CS5 will.

With procedural scripting, the objects that you are talking to; movie clips, buttons, textfields, are all there on the timeline, so there’s no mystery going into it. Everything is right there. Most classes, as perfectly as they are built, will require additional code in the FLA anyway.

I know about all of the benefits of class-based programming and it must be great to build modular code that is reusable – especially when you are working on a team – but I’m a one man show here.

So, I ventured to try to create a simple example of a class file to illustrate how to program and test it.

Begin by starting a new ActionScript file in Flash. Save it as NameCaller.as. When you’re building a class, the name of the class is the same name as the name of the file. We’ll start by writing out a typical class package:

package {
public class NameCaller extends MovieClip {
public function NameCaller() {


Save the file.
Start a new Flash ActionScript 3.0 file and also save it as NameCaller.fla. be sure to save it in the same location as the NameCaller.as class file. In the Properties panel, you’ll see a Class field. This is the document class. Enter NameCaller and hit enter. You shouldn’t see any warnings or errors when you do this. If you do, then you may have not saved the files in the same place.

In the Flash file, add a dynamic textfield to the stage and give it an instance name of output. Save the file and return to the NameCaller.as class file.

This really basic example will simply concatenate two variables with a sentence and display it in the dynamic textfield.

Since the class extends the MovieClip class, we’ll have to import that class. At the top of your script, after the package declaration, add the following:

import flash.display.MovieClip;

How do you know when you need to import something? Well, if you see compiler errors that complain about it, then you’ll have to add them.

Next, we’ll define our variables. In the class definition, add the following:

public var fname:String;
public var expletive:String;

Variables and functions can either be private or public. This has to do with security and access rights. Since these variables are public, we can use them outside of the class, such as in our fla file.

Every class has methods (functions) in it, but there’s one method that is required, which has the same name as the class. Add the following to the NameCaller function:

init(fname, expletive);

We’re going to define the init function now. I’ve seen this in common practice – that the main function isn’t doing much other than calling on another function.

Now, we can define the init function:

public function init(fname:String, expletive:String) {
output.text = fname + " is a complete " + expletive;

We’ve given this function two parameters: fname and expletive. By doing this, we can set those parameters when we call on this function later in the fla file. The dynamic textfield will receive the full message.

Be sure to save the class file and then go to the Fla file. In the Actions panel, add the following:

init("Joe Biden", "Asshole");

We don’t have to import the class because it’s a document class. Here, we didn’t use a class path and save the file in an obscure location, as in the following example:


We just saved the class file in the same location as the fla. If we were building a complete application that required multiple classes, then we would need to explore that more, but this is just a simple example.

When you test your Fla file, you should see the concatenated statement in the dynamic textfield.

Homework: Try adding input text fields that would allow users to enter in a name and expletive. Try adding a Combo box component that allows users to pick an expletive.

Here’s all of the code for the class:

package {
import flash.display.MovieClip;

public class NameCaller extends MovieClip {

public var fname:String;
public var expletive:String;

public function NameCaller() {
init(fname, expletive);
public function init(fname:String, expletive:String) {
output.text = fname + " is a complete " + expletive;

New Features of Flash CS5

Posted on: April 14th, 2010 by alemieux

So Adobe announced CS5 on Monday. I thought the presentation was pretty cool, but somehow, I was expecting more new features. All of the apps are now 64-bit, which will give it a great speed performance. As far as Flash goes, the new features are:

Text boxes that behave like those in InDesign. You can link text boxes together so that text will flow throughout them.

Spring feature of the Bones tool. Allows you to set a strength and dampening setting so that the bones objects bounce and behave like they are reacting to an external force.

There’s a publish setting in Flash to publish to the iPhone. I’ve talked about this before, but Apple isn’t going to allow this moving forward.

Terry White demonstrates the new features in this video:

Problems with the new Motion Tween model in Flash CS4

Posted on: March 19th, 2010 by alemieux

In this video, I’m talking about some of the challenges and differences between Classic Tweening and the new Motion Tween model in Flash CS4, particularly with Reversing Keyframes and Property Keyframes. Enjoy.

Problems with Motion Tween Model in Flash CS4 from Al Lemieux on Vimeo.

This blog has moved

Posted on: March 17th, 2010 by alemieux

This blog is now located at http://lemieuxdesign.blogspot.com/.
You will be automatically redirected in 30 seconds, or you may click here.

For feed subscribers, please update your feed subscriptions to