• 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


// 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 ();

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

'Free Member'-Only Content

You must be a 'Free Member' to see this content. With your access you will enjoy members-only content like this, HD video tutorials, and access to complete source code.

Ready To Join?
  • Sign up for 'Free Member' level now. Its free!
  • Sign up for 'Paid Member' level to enjoy much, much more! (Invite Only)
Already A Free Member?
  • Log in and enjoy!

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;

//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;

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;

//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 ();

Next Steps

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

Member Resources

'Free Member'-Only Content

You must be a 'Free Member' to see this content. With your access you will enjoy members-only content like this, HD video tutorials, and access to complete source code.

Ready To Join?
  • Sign up for 'Free Member' level now. Its free!
  • Sign up for 'Paid Member' level to enjoy much, much more! (Invite Only)
Already A Free Member?
  • Log in and enjoy!

Free Member Login

You are not currently logged in.






» Register
» Lost your Password?

Support Our Sponsors

Category

  • Industry News
  • Standards & Best Practices
  • Full Tutorials
  • RMC News
  • Events

Tag

3D AIR API AS3 AS3.5 Business C# Debugging Experimental Flash Flex Games HTML5 Java Loom Mobile Optimization Project Planning PushButtonEngine Robotlegs Smash Unity3D 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

I Am Great!

   

Latest Portfolio

  • Live Media Steaming ApplicationMay 20, 2013, 5:06 am
  • Museum Kiosk Touch ScreenNovember 15, 2012, 9:00 pm
  • Happy Birthday Mobile AppMarch 14, 2012, 5:55 pm
  • Official Robotlegs MVCS DiagramFebruary 24, 2012, 1:36 am

Latest News

  • Unity3D Top 5 News AnnouncementsMay 24, 2013, 3:10 am
  • Tutorial Series: Unity3D / C#May 24, 2013, 1:14 am
  • Intro to Loom Game EngineMay 19, 2013, 6:48 am
  • Cross Platform Mobile: Free TalkDecember 21, 2012, 7:14 am

Latest Tweets (@srivello)

  • The internet in Kuala Lumpur at 6Mbps is a totally different product than at the typical 1Mbps of archipelagic Asia. http://t.co/EV010rXILx
  • Very inspired by the #XBoxOne. The presentation's focus on non-game features is both bold and a bit scary as a gamer.
  • 3 hours into my Centipede clone using #2DToolkit for #Unity3D http://t.co/5yWsMQvHEU
  • @pixelplacement I've seen 'iTween Parameter Code Hinting' but anyone done a completely strong-typed (no hash) version of iTween?

© Copyright 2006 - 2013 - Rivello Multimedia Consulting - Flash / HTML5 / Unity3D Game And App Development With Tutorials