Author Topic: Enums in AS3  (Read 2574 times)

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Enums in AS3
« on: Fri, Dec 23, 2011 »
Hi,

I know we don't have Enums in AS3 as we do in C and I googled and read about several different "fix"es around this but couldn't choose which to use so I wanted to know what you guys do if you want to achieve such thing in AS3.

-tnx
blog, twitter, Check out my award winning game, Rot Gut:

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: Enums in AS3
« Reply #1 on: Fri, Dec 23, 2011 »
(usually static) var BLA:uint = 0;

 :'(

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Enums in AS3
« Reply #2 on: Fri, Dec 23, 2011 »
static var BLA:uint = 0;

 :'(

don't be sad, have this  :-*

So you put it inside a class and access it with ClassName.BLA ?
blog, twitter, Check out my award winning game, Rot Gut:

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: Enums in AS3
« Reply #3 on: Fri, Dec 23, 2011 »
  :-[

Yea. Sometimes the class contains other code, sometimes it's purely an 'enum'.

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Enums in AS3
« Reply #4 on: Sat, Dec 24, 2011 »
|-I
sometimes it's purely an 'enum'.

What do you mean by that?

I've seen classes that their members are objects and they are instantiated in ctor and then get asked if they are equal to another object, did youmean that?
blog, twitter, Check out my award winning game, Rot Gut:

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: Enums in AS3
« Reply #5 on: Sat, Dec 24, 2011 »
All I meant is I have a couple classes that contain nothing but a list of uints. Their only purpose is to be a fake enum.

For example class GameState is just

Code: [Select]
static var PLAYING:uint = 0;
static var POPUP_MENU:uint = 1;
static var ROUND_END:uint = 2;
etc

And nothing else.

John Hutchinson (Johntron247)

  • Commodore 256
  • Contributor
  • ****
  • Posts: 392
  • Karma: +1/-0
  • I can has lazerz?
    • View Profile
    • Level X Games
Re: Enums in AS3
« Reply #6 on: Sat, Dec 24, 2011 »
That's how I do it as well.  I tried some of the tricks online that get you closer to real enums but I've never really been happy with them.  It's much cleaner and easier to just use static constants and be done with it.  Oh!  That's one difference from what I see in your code there... const not var
Code: [Select]
static const PLAYING:uint = 0;
static const POPUP_MENU:uint = 1;
static const ROUND_END:uint = 2;


// then later
var gameState = GameState.PLAYING;

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: Enums in AS3
« Reply #7 on: Sat, Dec 24, 2011 »
Yea you're right, shouda been const.

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: Enums in AS3
« Reply #8 on: Tue, Jan 3, 2012 »
That's how I do it as well.  I tried some of the tricks online that get you closer to real enums but I've never really been happy with them.  It's much cleaner and easier to just use static constants and be done with it.  Oh!  That's one difference from what I see in your code there... const not var
Code: [Select]
static const PLAYING:uint = 0;
static const POPUP_MENU:uint = 1;
static const ROUND_END:uint = 2;


// then later
var gameState = GameState.PLAYING;

Thanks, it's very nice.  ;)
blog, twitter, Check out my award winning game, Rot Gut: