Learn to build a typesafe actionscript 3 enum object.
Must-Read Flash Programming Books
Why use an enum?
Enum object description
A quick example would be:
[ACTIONSCRIPT 3.0 CODE BLOCK]
var p:Person = new Person("Bob", "Barker", "active");
if(p.state == PersonState.ACTIVE) { Do Something }
This example says we should instantiate a Person object, with first name, Bob, last name Barker, and give them a state of "active", which gets parsed to the PersonState object as "ACTIVE". Now at any time in the life of the application we can say if(p.state == PersonState.STATE_NAME) { Do Something }.
The real power behind this is that we no longer require our memory if our IDE is as excellent as the free tool FlashDevelop. The Intellisense automatically pops up when we say if PersonState. - and the list will pop up for us! Lets talk about how to set this up.
Here's How:
Below we have the source for a DebugType class, with three standard static functions. The getDebugType function converts a string that you pass in, to the type - which makes it beautiful for strongly typing objects directly from XML Values. The toString function converts the type to a string so you can actually see what you are working with. Otherwise, its a bunch of static constants that just point back at itself saying "I'm my own type". Quite a nice little trick... here's the code:
[ACTIONSCRIPT 3.0 CODE BLOCK]
package {
public class DebugType {
public static const NONE:DebugType = new DebugType();
public static const TRACE:DebugType = new DebugType();
public static const TRACE_THROWERROR:DebugType = new DebugType();
public static const TRACE_THROWERROR_LOGREMOTELY:DebugType = new DebugType();
public static const THROWERROR:DebugType = new DebugType();
public static const THROWERROR_LOGREMOTELY:DebugType = new DebugType();
public static const LOGREMOTELY:DebugType = new DebugType();
public static function getDebugType(type:String):DebugType {
var retType:DebugType;
switch(type.toLowerCase()) {
case "logremotely":
retType = DebugType.LOGREMOTELY; break;
case "trace":
retType = DebugType.TRACE; break;
case "trace_throwerror":
retType = DebugType.TRACE_THROWERROR; break;
case "trace_throwerror_logremotely":
retType = DebugType.TRACE_THROWERROR_LOGREMOTELY; break;
case "throwerror":
retType = DebugType.THROWERROR; break;
case "throwerror_logremotely":
retType = DebugType.THROWERROR_LOGREMOTELY; break;
default:
retType = DebugType.NONE; break;
}
return retType;
}
public static function toString(a:DebugType):String {
var retType:String;
switch(a) {
case DebugType.LOGREMOTELY:
retType = "Log Error(s) Remotely Only"; break;
case DebugType.TRACE:
retType = "Trace Error(s) Only"; break;
case DebugType.TRACE_THROWERROR:
retType = "Trace and Throw Error(s)"; break;
case DebugType.TRACE_THROWERROR_LOGREMOTELY:
retType = "Trace, Throw, and Remotely Log Error(s)"; break;
case DebugType.THROWERROR:
retType = "Throw Error(s) Only"; break;
case DebugType.THROWERROR_LOGREMOTELY:
retType = "Throw, and Remotely Log Error(s)"; break;
default:
retType = "No Debug Type Selected"; break;
}
return retType;
}
}
}
The software to get the job done.
The latest news regarding Adobe Flash and Actionscript
- Build Bing Maps Flash/ActionScript Apps with AFC SDK
- However, Microsoft is not hanging ActionScript developers out to dry. In fact, the Redmond company has partnered with AFComponents in order to make ...
- New version of JavaScript approved
- This version would have contained such features as the namespaces that Adobe implemented for ActionScript. Those features are are not part of the newly ...
- FRONT-END Developer
- Programming is done in Actionscript 3.0 in a video player that was designed from scratch two years ago. The player is highly object-oriented and based on ...
- JetBrains ships IntelliJ Idea Java IDE upgrade
- In addition to that, all the advanced code editing features that we support for Flex (code completion, ActionScript refactorings, error highlighting and ...
Reader Feedback
Give me a shoutout if you have any questions, comments, or just want to tell me a better way to develop an AS3 Enum.
Go ahead, take your mind off life and enjoy some jokes below ;)
- Clean Web Jokes Homepage
- Aging Jokes
- Animal Jokes
- Bar Jokes
- Blind Jokes
- Blonde Jokes
- Business Jokes
- Computer Jokes
- Crazy Jokes
- Farmer Jokes
- Fishing Jokes
- Food Jokes
- Gender Jokes
- Golf Jokes
- Holiday Jokes
- Kids Jokes
- Lawyer Jokes
- Light Bulb Jokes
- Marriage Jokes
- Math Jokes
- Medical Jokes
- Military Jokes
- Music Jokes
- Office Jokes
- Parent Jokes
- Police Jokes
- Political Jokes
- Redneck Jokes
- Religious Jokes
- School Jokes
- Science Jokes
- Shopping Jokes
- Sport Jokes
- State Jokes
- Travel Jokes
- Yo Mama Jokes






![Adobe Creative Suite 4 Design Premium Upgrade [Mac]](http://ecx.images-amazon.com/images/I/41XZ7rvRBeL._SL75_.jpg)
Fetching new data from eBay now... please stand by



