• Home
  • Contact
  • Careers
  • Socialize With Us:
  • Send us Mail
  • Follow us on Twitter
  • Join our Facebook Group
  • /
  • Linkedin
  • /
  • Vimeo Videos
  • /
  • Youtube
  • /
  • RSS Feed
  • Search Site

  • About UsAwards & Bio
  • PortfolioOur Latest Work
  • TrainingTips & Tutorials
  • BlogGreat Articles

You are here: Home / Tag: AS3.5

Tag Archive for: AS3.5

Using Singletons in AS3

Category: Quick Tips     |     Tags: AS3, AS3.5

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!

  • Download the full source

[/private_Free member]

Using Enums in AS3

Category: Quick Tips     |     Tags: AS3, AS3.5

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!

  • Download the full source

[/private_Free member]

Tag

3D AIR API AS3 AS3.5 AssetStore Augmented Reality Business C# Charity Debugging Design Patterns DevDiary ECS Architecture Experimental Flash Flex Game Design Game Design Prototypes Games GUI HTML5 Java Loom Mobile MVCS Architecture Optimization Project Planning PushButtonEngine ReactiveExtensions Review Robotlegs Smash Testing Unity3D UnityApplicantTest WordPress WordPress Plugin

Brazilean Developers

  • Abendita.com
  • dclick.com.br
  • dm9.com.br
  • Fellyph Cintra
  • IgorCosta.org
  • MonadaSolucoes.com.br
  • PossibleWorldwide.com.br
  • Unit9.com

Developers

  • Adobe Blogs
  • Ben Forta
  • Colin Moock
  • Enrique Duvos
  • Flash Mobile Blog
  • Jess Freeman
  • Kevin Hoyt
  • Lee Brimelow
  • Paul Trani
  • Quasimondo
  • Renaun Erickson
  • Ryan Stewart

Free Assets

  • Free Sounds
  • HasGrafics

HTML5 Games

  • Closure JS Library
  • Eloquent JS Manual
  • Game Framework – CraftyJS
  • Game Framework – EaselJS

Italian Developers

  • alchimedia.com
  • corlan.org/
  • creativesource.it
  • dimix.it
  • fabiobiondi.com
  • gnstudio.com
  • Interpreting-tech.com/bemobile/
  • leonardorisuleo.info
  • lucamascaro.info
  • mart3.org
  • mxml.it
  • nxn.it
  • pirosoft.it
  • Preload.it
  • sonnati.wordpress.com/
  • webgriffe.com

Products

  • Adobe.com
  • Amazon Kindle E-Reader
  • ElectroServer
  • F*CSS
  • Flash Development Toolkit (FDT)
  • O'Reilly PureMVC Book
  • Samsung Galaxy Tablet
  • Unity3D

RMC

  • RMC Consulting

Spanish Developers

  • Flash Adictos
  • HTML Cinqo
  • Tutoriales Flash

Tutorial

  • Active Tuts
  • AS3-to-Unity3D Training Videos
  • Doing 2D in Unity3D
  • Learning C#
  • Unity3D Tutorials

Unity3D Games

  • AS3-to-Unity3D Training Videos
  • Doing 2D in Unity3D
  • Learning C#
  • Matt Eley's Blog
  • Unity3D
  • Unity3D Tools
  • Unity3D Tutorials

Interesting links

Besides are some interesting links for you! Enjoy your stay :)

Latest Portfolio

  • Coins And PlatformsMarch 19, 2014, 6:04 am
  • Paddle SoccerMarch 2, 2014, 9:13 pm
  • Spider StrikeFebruary 21, 2014, 4:19 am
  • Custom Game System APIJuly 8, 2013, 8:05 am

Latest News

  • RMC Primer: Everything Virtual Reality (VR)September 3, 2016, 10:29 am
  • Unity3D Architectures: EntitasJuly 29, 2016, 11:15 pm
  • RMC Primer: Get A Job In Game DevelopmentAugust 19, 2015, 10:18 am
  • Unity UI: Overview – Part 1 of 3December 10, 2014, 9:55 am

Archive

  • September 2016
  • July 2016
  • August 2015
  • December 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • December 2012
  • October 2012
  • September 2012
  • July 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • October 2011
  • September 2011
  • August 2011
  • June 2011
  • April 2011
  • March 2011
  • January 2011
  • December 2010
  • October 2010
  • September 2010
  • April 2010
  • March 2010
  • January 2010
  • October 2009
  • August 2009
  • June 2009
  • May 2009
  • April 2009
  • January 2009
  • December 2008
  • November 2008
  • August 2008
  • May 2008
  • April 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • August 2007
  • May 2007
  • January 2007
  • October 2006
  • April 2006
  • March 1999

© Copyright 2006 - 2023 - Rivello Multimedia Consulting - RMC by Samuel Asher Rivello