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
- Graphic Designer
- Technical skills to include Photoshop, Illustrator, Flash, ActionScript, Accessibility Awareness and CSS. The successful candidate will have examples of ...
- ActionScript for Multiplayer Games and Virtual Worlds
- ActionScript for Multiplayer Games and Virtual Worlds is not a comprehensive end-to-end guide to building your own Club Penguin or WebKinz or WoW from the ...
- MIPS Technologies Collaborates With Adobe to Optimize Flash Player 10.1 for ...
- In October, MIPS Technologies announced the release of a MIPS-optimized version of the ActionScript(TM) virtual machine (VM) that is used in Adobe Flash ...
- Kongregate opens the flood gates for MMO developers
- Developers can use Javascript, Actionscript, or REST APIs from their own backend to tap into features such as achievements, leaderboards, virtual goods, ...
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






