Adobe Max 2013: Best Gaming Sessions

I recently covered an Introduction To Adobe Game Developer Tools. With excitement and momentum (created primarily by Stage3D and its Starling Framework) we see proactive, positive marketing by Adobe for gaming and the Flash Platform. The community hopes this will help keep the Flash Platform in the minds of business leaders and developers as a viable technology for new projects.

Adobe recently announced the details for the annual Adobe Max conference. Thankfully, in 2013 we see a focus on gaming.

Adobe Max 2013

Adobe MAX 2013 will be at the L.A. Convention Center & Nokia Theatre L.A. LIVE on May 4 – 8, 2013

(From Adobe Marketing:) Adobe MAX is all about creativity and expressiveness. If you create, you won’t want to miss MAX. Designers, developers, strategists, video professionals, photographers, and more all come to MAX to exchange ideas and inspiration. Together with industry pros and visionaries, you’ll learn about the latest technologies, techniques, and strategies for delivering your best creative work. Come to MAX and explore how creativity is changing the word and what part you have to play in that change. And every full conference MAX pass includes a one year membership to Adobe Creative Cloud*

Adobe Max 2013: Gaming Sessions

Here are the game-related sessions we can look forward-to;

ID TITLE DATE TYPE
L7804 Building a Platformer Game with the Starling Framework Monday 5:00 PM, Tuesday 3:00 PM Lab
L7902 Developing Multiplatform Games with the Adobe Gaming SDK Monday 12:45 PM, Tuesday 12:30 PM Lab
PB7682 Building Games with the Adobe Gaming SDK Sunday 9:00 AM Preconference BYOD Lab
PB7683 Advanced Flash Gaming Development with the Latest Adobe Technologies Sunday 9:00 AM Preconference BYOD Lab
S7802 Adobe Gaming Roadmap Monday 2:00 PM Session
S7805 Wired Up: Integrated Tools for Game Creation Tuesday 1:00 PM Session
S7862 Becoming a Successful Game Developer with Adobe Flash Tuesday 4:00 PM Session
S7904 ActionScript Game Frameworks Panel Wednesday 9:30 AM Session
S8022 Mastering Multiplayer Stage3D and AIR game development for mobile devices Monday 2:00 PM Session
S8202 Extending Mobile Games with AIR Native Extensions (ANEs) Tuesday 8:30 AM Session
S8362 Next-Generation Runtime for Adobe Gaming Tuesday 8:30 AM Session

Next Steps

ActionScript 4.0 Revealed

Over the past year I’ve been learning more HTML5 frameworks. Frequent leaders of our site here may remember I’ve done some analysis on HTML5 Game Frameworks as well as HTML5 App Frameworks. A major significant lack in the HTML5 ‘solution’ is the limitations of JavaScript. I was delighted to come across the official Adobe Roadmap (See ‘Members Resources’ below) for the FlashPlatform. An exciting inclusion in the roadmap is what’s up for “ActionScript Next” (Codename) or as I choose to call it ActionScript 4.0.

UPDATE (June, 2012): Adobe announces the plan for concurrency in Flash Player and AIRWorkers.

UPDATE (January, 2013): ActionScript “Next” (aka 4.0 as I call it here) has been explicitly removed from the Adobe Roadmap.

UPDATE (August, 2013): The offerings in ActionScript are vast, but to see a more powerful language, I recommend to take a look at C# in my free, HD video training series on “Unity3D & C#“. Check it out!

ActionScript 4

The range of applications and content for ActionScript has shifted significantly in recent years, while the ActionScript 3 language remains virtually unchanged since its introduction in 2006. Adobe believes it is time to revise the language to carefully steer its further evolution towards greater expressiveness as well as productivity and performance gains.

From a language design standpoint, Adobe uses the following assumptions as a guide for next-generation ActionScript development:

  • Increasing demand for long-term productivity benefits such as robustness, modularity, and maintainability to complement shorter-term productivity benefits characteristic of scripting languages, such as speed of development
  • Demand for high performance increases
  • Demand for hardware utilization increases

First, Adobe plans to make significant performance increases in the short term with a goal of continuing performance improvements over the long term. Performance is the primary goal when we approach how to evolve ActionScript. Second, Adobe aims to increase developer productivity by simplifying the language, improving tool support, and boosting bug prevention. Finally, having reduced unnecessary complexity, we will be in a position to innovate within the Flash runtimes much more quickly.

Features Currently In Discussion;

  • Stringent static typing as default, with optional dynamic typing: Most stretches of most programs are expected to benefit from static typing. However, ActionScript 3 tends to lapse into dynamic typing all too easily in places where absolutely stringent static typing would be preferable. This will be corrected. Dynamic typing will still be available when needed, but it will no longer be the default for ActionScript, and it will need to be enabled explicitly.
  • Type inference: Type declarations will only be necessary in certain strategic places. Everywhere else the compiler will automatically infer suitable type declarations and treat the whole program as statically typed, even though the programmer does not have to state any types. Thus the convenience of untyped programming can be approximated quite well, while providing the performance advantages of typed programming.
  • Hardware-oriented numeric types: For example, int , uint , float , float4 , byte , short , long , etc. (the exact set of types is still under discussion). Currently in ActionScript 3 integer values can overflow into floating point values. This will be changed so that numeric operations will never change the underlying representation of the numeric. We foresee this addition greatly reducing implementation complexity and improving runtime performance.

These are just a couple of areas that we are focusing on. We will update this document as our thinking evolves and solidifies around how the language and virtual machine will change.

Compatibility

Its is stated that AS4 will not be completely compatible with AS3. So maybe there will be a compiler option and one must choose EITHER one or the other (similar to the mutual exclusive option between AS3 and AS2. Depending on the amount of changes in AS4 we may see a new virtual machine inside the player designed to run only the AS4. Currently there are two VM’s – one for AS3 and one for older ActionScript.

Wishlist

Many developers have been dreaming (ex. here & here) of features for ActionScript for ages. Some features I would love to see;

  • Abstract Classes with Abstract Methods (ASL-18) – Well, do I have to have to say something about that wish? Basically abstract classes are such an essential thing, I am still wondering how Action Script made it to 3.0 without them. Just documenting which Methods must be overridden is not enough. And the known workarounds are really… well… hm… forget it – this is a compiler thing, which cannot be checked at runtime.
  • Generics (FP-811) – The Vector class is a good start – but it’s not well supported in Flex 3 (keyword: data binding) and it’s not a generic concept. There should be something like Generics in Java that provide type checking at compile time, but can also be used for any custom class, just like in Java.
  • Enums – While I have a (almost) perfect workaround for Enums in AS3, it would be great to see native language support.
  • Singletons – I have a fantastic workaround for Singletons in AS3
  • Improved ‘Event Listener’ syntax and performance. I like the features offered by the AS3-Signals project.
  • Operator Overloading (ASL-10) – Still missing it in Java and this is, where Action Script could actually beat Java. I don’t want to have another equals method for comparing arbitrary classes for equality – I want to be able to simply override the == operator to be able to compare any two objects for equality. Or the + operator for concatenating two data structures. Just like in C++ or smalltalk.
  • Method Overloading (ASL-9) – While ActionScript provides an easy way to simplify methods with long parameter lists using default values for parameters it’s not enough to justify not having method overloading. I do not want to have to write methods like doSomethingWithString(value:String), doSomethingWithInt(value:int), doSomethingWithObjectA(value:ObjectA),…

ActionScript 4.0 Code Samples (A Proposal)

AbstractClassDemo

[actionscript3]
package
{
//class must be subclassed before instantiation
abstract public class AbstractClassDemo
{
public function AbstractClassDemo()
{
}
}
}
[/actionscript3]

AbstractMethodDemo

[actionscript3]
package
{
public class AbstractMethodDemo
{
public function AbstractMethodDemo()
{
}

//Method must be overridden before usage
abstract public function sampleMethod () : void
{
}
}
}
[/actionscript3]

DestructorDemo

[actionscript3]
package
{
public class DestructorDemo
{
//constructor
public function DestructorDemo()
{
}
//destructor, called upon instance deletion
public function ~DestructorDemo()
{
}
}
}
[/actionscript3]

Enums

[actionscript3]
package
{
public enum EnumSample
{
ENUM_SAMPLE_A;
ENUM_SAMPLE_B;
}
}
[/actionscript3]
[actionscript3]
package
{
public class EnumDemo
{
public function EnumDemo()
{
trace (ENUM_SAMPLE_A); //[EnumSample ENUM_SAMPLE_A]
trace (ENUM_SAMPLE_B); //[EnumSample ENUM_SAMPLE_B]
trace (ENUM_SAMPLE_A is EnumSample); //true
trace (ENUM_SAMPLE_A is EnumSample); //true
trace (ENUM_SAMPLE_A == ENUM_SAMPLE_B); //false
}
}
}
[/actionscript3]

GenericsDemo

[actionscript3]
package
{
public class GenericsDemo <AGE_TYPE, NAME_TYPE>
{
private var _age : AGE_TYPE;
private var _name : NAME_TYPE;

public function GenericsDemo(AGE_TYPE : aAge, NAME_TYPE, aName)
{
_age = aAge;
_name = aName;

//Later, in use, declare types at runtime for the generic
//var genericsDemo : GenericsDemo<Float,String> = new GenericsDemo<Float,String> (10.0, "Flash");
}
}
}

[/actionscript3]

MethodOverloadingDemo

[actionscript3]
package
{
public class MethodOverloadingDemo
{
public function MethodOverloadingDemo()
{

//The implementation of this AS3 Syntax
// can now be overloaded in AS34
_sampleMethod();
_sampleMethod(10.0);
_sampleMethod("10.0");
}

/**
*
* @return void
*
*/
override public function _sampleMethod () : void
{
trace ("Parameters – None");
}

/**
*
* @return void
*
*/
override public function _sampleMethod (aValue_float : Float) : void
{
trace ("Parameters – Float: " + aValue_float);
}

/**
*
* @return void
*
*/
override public function _sampleMethod (aValue_str : String) : void
{
trace ("Parameters – string: " + aValue_string);
}

}
}
[/actionscript3]

NumericTypesDemo

[actionscript3]
package
{
public class NumericTypesDemo
{
public function NumericTypesDemo()
{
//specificity helps ram usage
var sample_int : int = 10;
var sample_uint : uint = 10;
var sample_float : Float = 10.0;
var sample_float4 : Float4= 10.0;
var sample_byte : Byte = 1;
var sample_short : Short = 10;
var sample_long : Long = 10;
}
}
}
[/actionscript3]

OperatorOverloadingDemo

[actionscript3]
<pre>package
{
public class OperatorOverloadingDemo
{
public function OperatorOverloadingDemo()
{
//The implementation of this valid AS3 Syntax
// can now be overloaded in AS34
this + 10.0;
this – 10.0;
this * 10.0;
this / 10.0;
this == 10.0;
this += 10.0;
this -= 10.0;
this *= 10.0;
this /= 10.0;

//Etc…

}

/**
* Add
*
* @return Float
*
*/
override public function operator== (aValue_float : Float) : Float
{
// Mimic default implementation
if (super.operator==(aValue_float) ) {
return true;
} else {
return false;
}
}

/**
* Add
*
* @return Float
*
*/
override public function operator+ (aValue_float : Float) : Float
{
// Mimic default implementation
this = super.operator+(aValue_float);
return this.toFloat();
}

/**
* Etc…
*
*
*/

}
}
[/actionscript3]

SingletonDemo

[actionscript3]
package
{
public class SingletonDemo
{
//private constructor mean ‘Singleton’
private function SingletonDemo()
{
}
}
}
[/actionscript3]

StaticTypingDemo

[actionscript3]
package
{
public class StaticTypingDemo
{
public function StaticTypingDemo()
{
//compiler determines type by default
var sample1 = 10;
trace ("sample1: " + sample1); //10
trace (sample1 is uint); //true

var sample2 = -10;
trace ("sample2: " + sample2); //-10
trace (sample2 is int); //true

var sample3 = 10.0;
trace ("sample3: " + sample3); //10.0
trace (sample3 is Float); //true

//dynamic type in strategic places
var sample4 : int = 10.0 as int;
trace ("sample4: " + sample4); //10
trace (sample4 is int); //true

}
}
}
[/actionscript3]

Next Steps

  • What would you like to see in AS4? Comment below!
  • Download the Official Adobe Roadmap for Flash / ActionScript 4.0 (See ‘Member Resources’ below)

Member Resources

[private_Free member]Enjoy this members-only content!

[/private_Free member]

Unity3D & C# Training

The offerings in ActionScript are vast, but to see a more powerful language, I recommend to take a look at C#.

Some powerful C# features we love are;

  • Struct
  • Partial Classes
  • True Singleton (private constructor)
  • Ref/Out
  • Full Generics (AS3 has only Vector)
  • Delegates/Actions/Predicates/Lamda
  • Threads
  • Extension Methods,
  • Operator Overloading,

All of these features and more, plus Unity3D & C# best practices are included in my free, HD video training series on “Unity3D & C#“. Check it out!

vimeo_screenflow_video_thumbnail_UWK_poster_v1

 

Fixing Memory Leaks with Adobe Flash Builder

On a recent project, we had a performance problem. The AIR project’s requirements include the heavy adding/removing of UI elements and over time we could easily see the performance slowed. We knew there was a something wrong. It was a memory leak. A memory leak starts when an object is stored in memory but cannot be accessed by the running code. When the undesired object cannot be freed from memory, and is not usable, it is a leak. Over time the application may leak (or re-leak the same issue) more and more. Eventually the application may show signs of the leak or even become unusable.

User Experience Symptoms Of  A Memory Leak

  • During regular use the application becomes more and more sluggish/slow. If there is nothing ‘new happening’ onscreen and no heavy ‘rendering’ it is more obvious to notice the Framerate-per-second (FPS) lower. You can use a small debug window (such as Hi-Res-Stats formerly MrDoobs Stats) to show the current FPS and estimated ram usage to help you notice this. If you see the FPS run at 30 for example during the first minute of use and 20 after 5 minutes, there may be a memory leak.
  • The application quits suddenly. This could be for many reasons, but it may be that the application runs out of memory.
  • Flash throws the memory-specific error ‘flash.errors.MemoryError’
Even if you see one of these symptoms it may not be obvious that there is a problem or that the problem is a memory issue. Or perhaps your development machine is high powered with ample RAM, yet your target user’s machines are slow. You don’t see the issue, but your users will. So how can we diagnose the issue. Luckily, the Flash Builder IDE has a ‘Profiler’. This program runs alongside your application and serves several key roles. You can monitor your applications USAGE of memory over time, and see a live list of all OBJECTS in memory (including references to those objects).

Profiling To Find Evidence Of A Memory Leak

  • Run your application with the Flash Builder Profiler. Run -> Profile As… -> etc…
  • Watch the ‘Memory Usage’ Panel
  • Look at the curves of Peak Memory (Red) and Current Memory (Blue). The analysis is totally application dependent. In your particular application, if you expect memory not to grow, but you see it grow, that is a problem. If you expect the memory to drop (UI removed from stage, arrays and vectors emptied, etc…) and you don’t see it drop, that is a problem. Herein lies the art of memory profiling. Consider to add a button to ‘Reset Application’, then click it and see that indeed the Current Memory drops to zero (0).
  • Watch the ‘Live Objects’ panel. Compare the 1. ‘Cumulative Instances’ and 2. ‘Instances’. For each object. #1 shows the total objects every created since the application started and #2 shows only those currently in memory. If these numbers are the same, and should not be, that is a problem. Perhaps you feel you have deleted a sprite from the stage or deleted another object from memory yet it still exists.


Tools And Tips For Finding And Fixing Memory Leaks (Must Read!)

If you want to play with a simple example you can download the example below (See ‘Member Resources’) below.

Example 1: Without Memory Leak

[actionscript3]
package
{
import flash.display.Sprite;
import flash.events.Event;

//USE A LOW FRAMERATE, SO WE CAN STUDY CLOSELY
[SWF(frameRate="1")]
public class MemoryLeakDemo extends Sprite
{

private var listOfDots_vector:Vector.<CustomDot>;
public function MemoryLeakDemo()
{
//REPEAT SOME CODE EVERY SECOND
addEventListener(Event.ENTER_FRAME, _onEnterFrame);

//CREATE A LIST
listOfDots_vector = new Vector.<CustomDot>();
}

protected function _onEnterFrame(event:Event):void
{
//EVERY FRAME WE…

//1. CREATE A NEW ‘DOT’ (A Red Circle Sprite)
//MEMORY NOTE: ‘var’ is a temporary variable.
//So CustomDot has 0 (permanent) references
var customDot : CustomDot = new CustomDot();

//2. ADD TO THE STAGE
//MEMORY NOTE: So CustomDot has 1 (permanent) reference; ‘this’
addChild(customDot);

//3. REMOVE TO THE STAGE
//MEMORY NOTE: So CustomDot has 0 reference
removeChild(customDot);

//So…
//THERE IS NO LEAK
//The GC will *mark* the ‘customDot’ as having 0 references and
//The GC will *sweep* it away from memory.

}

}
}
[/actionscript3]

Example 2: With Memory Leak

[actionscript3]
package
{
import flash.display.Sprite;
import flash.events.Event;

//USE A LOW FRAMERATE, SO WE CAN STUDY CLOSELY
[SWF(frameRate="1")]
public class MemoryLeakDemo extends Sprite
{

private var listOfDots_vector:Vector.<CustomDot>;
public function MemoryLeakDemo()
{
//REPEAT SOME CODE EVERY SECOND
addEventListener(Event.ENTER_FRAME, _onEnterFrame);

//CREATE A LIST
listOfDots_vector = new Vector.<CustomDot>();
}

protected function _onEnterFrame(event:Event):void
{
//EVERY FRAME WE…

//1. CREATE A NEW ‘DOT’ (A Red Circle Sprite)
//MEMORY NOTE: ‘var’ is a temporary variable.
// So CustomDot has 0 (permanent) references
var customDot : CustomDot = new CustomDot();

//2. ADD TO THE STAGE
//MEMORY NOTE: So CustomDot has 1 (permanent) reference; ‘this’
addChild(customDot);

//2B. CREATE ANOTHER REFERENCE TO THE DOT
listOfDots_vector.push(customDot);

//3. REMOVE TO THE STAGE
//MEMORY NOTE: So CustomDot has 0 reference
removeChild(customDot);

//So…
//THERE *IS* A LEAK
//While we are correctly calling removeChild
//There is a reference left in ‘2B’ above.

}

}
}
[/actionscript3]

Next Steps

  • Download the code and check it out! (See Member Resources)
  • Comment below with your thoughts.
  • NOTE: Flash Builder 4.7 (BETA2) has new Profiler called “Monocle“. It looks very exciting, yet this article focuses on the currently available (non-BETA) profiler.

Member Resources

[private_Free member]Enjoy this members-only content!

[/private_Free member]

Robotlegs Framework Template

Robotlegs (from Robotlegs.org) is  a great architectural framework for AS3. It works for both Flash and Flex projects. I have been a fan since the beginnings of the framework and I even created the official “Robotlegs Framework Diagram“.

One of the drawbacks of using an architectural framework is the time required to setup the project. To help new developers, veteran developers, and myself, I create and update several templates for Robotlegs (RL). Each is a complete publishable “Hello World” type project. When I start any new RL project I begin with one of these Robotlegs Templates (RLT).

It kicks ass, enjoy!

Screenshots

It is a simple app. (Note images may vary slightly depending on template)

Mix-ins

I combine RL with some other fantastic technologies in some templates.

Next Steps

  • RLT_Web_Flex – The original! (See ‘Member Resources’ below)
  • RLT_Web_Flex_AS3Signals – My favorite! (See ‘Member Resources’ below)
  • RLT_Web_Flex_AS3Signals_BabelFX – (See ‘Member Resources’ below)
  • RLT_AIR_FlexMobile_AS3Signals_BabelFX – (See ‘Member Resources’ below)
  • RLT_AIR_FlexMobile_AS3Signals_Multiplayer – (See ‘Member Resources’ below)

Member Resources

[private_Free member]Enjoy this members-only content!

[/private_Free member]

FlyerGame – One Game, Many Many Frameworks

I wanted to test out a few game frameworks learn more about AS3, Unity, HTML5, and other platforms. Here is a complete list of many, many versions with full source code (See ‘Members Resources’ below).

UPDATE: A new contender in the HTML5/JavaScript gaming space is phaser.io. I may add a demo to this page soon. Leave a comment if you’d like to see it.

Articles

I wrote ‘Flyer Game’ for a series of articles I wrote for Adobe’s “Inspire” (formerly ‘EDGE’) online magazine. To appreciate the HTML5 versions of the game, its great to look back at the general game theory as well as the Flash theory shown in these articles.

Downloads of FlyerGame

I provide full source-code to several versions of the FlyerGame. You can compare how each works, and learn more about gaming frameworks that way.

[nonmember]
FLASH VERSIONS

  • 1. Flash Pro and AS3 (Very Simple) – [Download in ‘Members Resources’ below]
  • 2. AS3 and PushButtonEngine (Component-Based) [PBEv1] – [Download in ‘Members Resources’ below]
  • 3. AS3 and PushButtonEngine (Component-Based) [PBEv2] – [Download in ‘Members Resources’ below]
  • 4. AS3 Stage3D [Starling Framework] (Very Simple) – [Download in ‘Members Resources’ below]
  • 5. AS3 Stage3D [Starling Framework] (OOP Version) – [Download in ‘Members Resources’ below]
  • 6. AS3 and Smash Framework – [Download in ‘Members Resources’ below]
  • 7. AS3 and Flixel (Coming soon!)
  • 8. AS3 and FlashPunk (Coming soon!)

OTHER VERSIONS

  • Unity3D w/ C# – [Download in ‘Members Resources’ below]
  • Loom w/ LoomScript – [Download in ‘Members Resources’ below]

HTML5 VERSIONS

  • EaselJS Framework – [Download in ‘Members Resources’ below]
  • ImpactJS Framework – [Download in ‘Members Resources’ below]
  • CraftyJS Framework – [Download in ‘Members Resources’ below]
  • MelonJS Framework – [Download in ‘Members Resources’ below]
  • Spaceport.io Framework – [Download in ‘Members Resources’ below]
  • LimeJS Framework – Github Source (Coming soon!)

[/nonmember]

Next Steps

  • Wow, there is so much content here!
  • Are you new to gaming? There is tons of gaming basics in this posts and code.
  • Are you a veteran? Learn to compare/contrast each framework for yourself using the source code (See ‘Member Resources’ below).

Member Resources

[private_Free member]Enjoy this members-only content!
FLASH VERSIONS

OTHER VERSIONS

HTML5 VERSIONS

  • EaselJS Framework – Github Source (Simple, like #1 above)
  • ImpactJS Framework – Github Source (Simple, like #1 above)
  • CraftyJS Framework – Github Source (Component-based like #2 above)
  • MelonJS Framework – Github Source (Simple, like #1 above)
  • Spaceport.io Framework – Github Source (Simple, like #1 above)
  • LimeJS Framework – Github Source (Coming soon!)

[/private_Free member]

Polls

[polldaddy poll=6052370]

Using Singletons in AS3

The Singleton design pattern requires a class to have exactly one instance – preventing multiple instantiation.

The pattern is very useful – including utility classes that manage ‘one thing’ throughout the entirety of your application. Singletons are not natively supporting in AS3. Why? I have no idea. It would have been nice. Perhaps it will be included in the upcoming ActionScript 4.0 when it is released.

I show two styles. Only one style is needed. Learn each one and then choose your favorite!

Example

[actionscript3 light=”true”]

// TWO STYLES ARE SHOWN

// *******************************************
// DEMO 1 – View the Console Output (getInstance() Required)
// *******************************************
var MyCustomSingleton1 : CustomSingleton1 = CustomSingleton1.getInstance();
MyCustomSingleton1.traceTheSecretPhrase();
MyCustomSingleton1.secretePhrase = "Now the value has changed in 1.";
MyCustomSingleton1.traceTheSecretPhrase();

// *******************************************
// DEMO 2 – View the Console Output (getInstance() *NOT* Required)
// *******************************************
CustomSingleton2.traceTheSecretPhrase();
CustomSingleton2.secretePhrase = "Now the value has changed in 2.";
CustomSingleton2.traceTheSecretPhrase();

// *******************************************
// DEMO – Impossible – This will show an error
// *******************************************
//var myFailedCustomSingleton1 = new MyCustomSingleton1 ();
//var myFailedCustomSingleton2 = new MyCustomSingleton2 ();
[/actionscript3]

The Case Against Singletons

Not everything in your application should be a Singleton. Its a tool to be used sparingly. In face there is active debate (here, and here) if Singletons are actually the devil.
I say Singletons are NOT the devil. But don’t take my word for it see those debates.

Next Steps

  • Don’t understand me? I don’t blame you. It’s crazy.
  • Check out the source (See ‘Member Resources’ below) and tell me what you think in the comments below!

Member Resources

[private_Free member]Enjoy this members-only content!

[/private_Free member]

Using Enums in AS3

Enums are my favorite community developed language feature!!!

UPDATED: I have incorporated all comments into a new version of my demo, and updated the post and source code! Old comments are cleared.

An Enum is a kind of variable that is not natively available in ActionScript 3.0, but can be found in other languages such as C++. Perhaps Enums will be included in the upcoming ActionScript 4.0 when it is released.

Basically – An Enum is a type with a restricted set of values. Typically developers use a string to hold simple state variables such as this;

[actionscript3 light=”true”]
//USING STRINGS (NOT ENUMS)
public static var STATE_ENABLED : String = "STATE_ENABLED";
public static var STATE_DISABLED : String = "STATE_DISABLED";
private var _currentState_str : String = STATE_ENABLED;
[/actionscript3]

Is this familiar? I’m sure it is. By using the static variable the benefit is that developers are less likely to misspell the name of one of these values due to helpful authortime and compile time errors. However the type is stored as a simple string so the developer *CAN* easily pass the wrong string in there (because ANY string is ‘correct’ to the compiler’). This is where Enums are great. Enums would work like this;

[actionscript3 light=”true”]
//USING ENUMS

// 1. STRONG TYPED & NICE USAGE
var current_estate : StateEnum = StateEnum.Connecting;

// traces ‘Connecting’. Nice!
trace ("Instance : " + current_estate);

// traces ‘true’
trace ("TypeCheck : " + (current_estate is StateEnum) );

// trace ‘true’ – This is the most common usage.
// Checking if a StateEnum instance matches a kind of StateEnum
trace ("Match? : " + (current_estate == StateEnum.Connecting) );

// 2. PROPERLY THROWS AN ERROR – YOU CAN’T INSTANTIATE StateEnum Outside of StateEnum.as
//var local_enum : StateEnum = new StateEnum ();

[/actionscript3]

Next Steps

  • Don’t understand me? I don’t blame you. It’s crazy. Check out the source (See ‘Member Resources’ below).

Member Resources

[private_Free member]Enjoy this members-only content!

[/private_Free member]

Unity3D Exports To Flash Contest Winners

As EDGE online reportsTail Drift has been selected as the winner of Unity’s Flash In A Flash Creation Contest, which tasked entrants with porting Unity-authored games to Adobe Flash.

Developer Cameron Owen has won $20,000 for his flight-based arcade racer, which was selected ahead of more than 500 fellow entrants.

Unity Technologies‘ Flash development lead Lucas Meijer said: “Not only is Tail Drift incredibly fun, but it also shows off both the amazing technology and fast development capabilities of Unity.

“It’s extremely gratifying to see the development community adopt and take off at such a rapid pace with the new beta, and we can’t wait to see the stellar work that is still in store.”

CEO David Helgason added: “This was a thrilling contest for all of us at Unity. Our engineers have created some terrific technology for the Flash platform and it’s truly inspiring to see so many developers adopt and create such amazing games so quickly.

Runner Ups

Three games were named runners-up, and the developers of each receive $1,00, Unity Pro with iOS Pro, and an iPad 2. A further six games  get Unity Pro with iOS Pro.

Honorable Mention

Las Viditas – Comparing ActionScript 3.0 and 7 Rules for Biological Life

Las Viditas (The Little Lifes) is an exploration project which compares ActionScript 3.0 programming concepts and structure to the 7 criteria for biological life.

You can see the Live Online Demo. I originally presented this project on a fantastic 360|Flex sponsored 7-Day cruise in the Caribbean several years back. What a great event! Finally, its all available now online..

I always find it fascinating to compare the technical world and the biological world. There is even an area of technological innovation where engineers study animals to influence new robotics designs. Here is a great Ted.com video of Robert Full Learning From Gecko Lizards. In my simple demo I learned a lot too, and am inspired with many game ideas too.

See Screenshot

The ecosystem on the right is the “petri dish” where the green viditas grow and move. There intelligence guides them to eat the blue ‘food’ and bounce off the walls. As they eat, they grow. As they starve, they shrink. Too much time without food, and they will permanently die.

Experiment with the settings and see how the population’s survival rate changes.

The sliders on the left allow for several changes such as;

  • Simulation Speed
  • Viditas Population Size
  • Food regeneration frequency
  • Food amount that is created each distribution

Watch Slideshow

[slideshare id=11770278]

Next Steps

  • Run the Live Online Demo.
  • Download the full source code (See ‘Member Resources’ below).

Member Resources

[private_Free member]Enjoy this members-only content!

[/private_Free member]

Tutorial Series: ActionScript 3.0

Learn Adobe’s ActionScript 3.0 – From Basics to Advanced

ActionScript 3.0 (AS3) is a powerful object-oriented programming language with similiar roots to JavaScript. One could say that ActionScript 2.0 was equivalent to JavaScript and AS3 is a much more mature version with support for classes, interfaces, namespaces, events, and more. This video series is designed to give new programmers a perfect place to start. There is also content for advanced programmers too.

Next Steps

Download the complete tutorial source code (See ‘Members Resources’ below) and watch these great videos:

1. IDE (Code Editors)

  • 1.1 Flash Builder: Install & Project Setup (See ‘Resources’ below) (Watch Video)
  • 1.2 Flash Professional: Install & Project Setup (See ‘Members Resources’ below)
  • 1.3 FDT: Install & Project Setup (See ‘Members Resources’ below)

2. Basic Programing (via Flash Builder)

  • 2.1 AS3 Basics With Cocktails: (See ‘Members Resources’ below)

3. Advanced Programming (via Flash Builder)

  • 3.1 AS3 OOP Programming With Cocktails: (Coming Soon…)
  • 3.2 Design Patterns With Cocktails: (Coming Soon…)

4. Frameworks (via Flash Builder)

Resources

Member Resources

[private_Free member]Enjoy this members-only content!

  • Download the complete tutorial source code
  • Click the video thumbnails below to watch the videos.

[tubepress mode=”vimeoChannel” vimeoChannelValue=”285406″ hqThumbs=”false” ]
[/private_Free member]

Want More Video Tutorials?

[polldaddy poll=5983808]