Monday, 30 November 2009

8 things that annoy me about ActionScript3

  1. TextField.text can't be set to a number or object, only a String (unlike trace() for example, which will toString() anything you throw at it). There is no logical reason for this that I can see, and makes for some ugly code with String() casts everywhere. You can't really get around it by extending TextField either, if you want a designer to be able to manually move the textfield on the stage in Flash, which I always do.
  2. You can't tell if a key is down. I don't agree that this is a security threat, and it's a pain when you're doing games.
  3. No access to stage before addedToStage. I can't really see the reason why this is the case, and it can make code a lot more verbose, as you can't use stage in your constructors, leading to an extra layer of listeners and complexity. And it's worse if you're not actually extending DisplayObject. In my view, stage is a natural Singleton, and generally I treat it as such nowadays by keeping a static reference in one of my classes.
  4. Events and all those string constants. I always thought there was something fishy about ActionScript events (like how many custom ones you need), and the brilliant example set by Robert Penner's Signals has proved it to me. I've been using Signals on my latest project and filing bug reports (and the odd fix), which Rob pretty much always implements within a day. This is an awesome open source project that gets better by the day - you will never want to use Events again!
  5. You can't tell if the mouse is hidden. Why have a Mouse.hide() without Mouse.isHidden? It makes no sense, and if you call Mouse.hide() repeatedly it makes the cursor flicker, which again I can't understand as Flash should know not to hide it if it's already hidden. I have created a simple MouseManager class to get round this, but again, why should I have to. Also, I think there is a potential issue around right-clicking showing a hidden mouse without notifying you. While we're on the subject of the mouse, for games you really want to be able to set the cursor position, as you can I think in Unity3D, and have a truly custom right-click, as you can in Silverlight 4.
  6. The video API is just wrong. Do you know your netstream from your netconnection? None of these things make sense. It should just be videoPlayer.play("video.flv") right?
  7. The timeline can't destroy movieclips, only remove them from the stage, and if they have any listeners they can't be garbage collected, so playing timelines is a memory leak minefield.
  8. There are no convenience functions for anything, anywhere. Thanks guys.

13 comments:

footloosemoose said...

wow - awesome rant! :)

Kyle said...

I've run afoul of basically all of these as well. The TextField and Stage access things especially piss me off. All. The. Time.

stanosmith said...

I especially agree with #6 about the video API. Why convolute the whole thing with so many extraneous items!

Owen said...

I can't say many of these things annoy me that much. If I ever get too annoyed, a quick reprisal of as2 makes me realise how good we have it :) Events are a little ropey though and the timeline is generally in a shocking state.

I personally like the separation of video into netstream, netconnection etc. The thing is that a netstream is for any streaming media, not just for video. A netconnection is useful for sockets or data transfer. If you want to have basic video, then there's always the VideoPlayer class.

I do think that Flash has lost its focus on games and is trying to be all things to all people, which is great in many ways, but makes for a more sprawling, irritant prone language. However, I think Adobe get less credit than they deserve for listening to developers and fixing stuff. 10.1 promises to be a great release...

Chris said...

Couple of thoughts:

I'm not sure Flash ever had a focus as a games development platform to lose - it's been pushed, punched and tweaked in that direction by content creators who have adapted to its timeline / animation working model.

When it comes to video - Silverlight walks all over it in terms of ease of deployment, which is only *slightly* frustrating ;)

And you can detect if a key is down, just not natively, Check here

Lionga said...

1. Makes perfect sense TextField.text is a string thats why you can only assign strings
2. Make a little helper class its soooo easy
3. You got the logical solution youself
4. You are right on that one
5. I never used that.
6. See Point 5
7. Do you understand garbage collection? Makes perfect sense that objects that have listners dont get collected. You might use weak references.
8. LOL

Iain said...

@owen Good point - ActionScript has come a long way, and AS3 is generally a pretty nice language to work with. Re. netstream etc, look at how many magic strings there are in the API and callbacks. Very dated.

@Chris the key detection thing is something I have been working in my new open source project - details soon.

@Lionga - function set text(_text:Object) would have worked just as well for the textfield API and saved us a bit the of work. Overloaded functions would be even better.

I absolutely understand garbage collection, my point was that Flash does some things automatically when the playhead moves that can be dangerous, whereas this was a problem in AVM1. It's probably the reason so many developers completely shun the timeline.

Snake said...

Nice list
I agree with most of it

Another thing that annoys me personally is that you can't make private constructors. (I can't make a simple singleton class like I would want to) It's not that I suffer from it or anything, it just reminds me that actionscript could be a more 'mature' language than what it is now.

gludion said...

Not only Flash users have "problems" with the timeline: Adobe devs themselves somewhat forgot the timeline. After 4 years, gotoAndStop() still not working correctly !! (though probably working "enough" for Java-style developpers)

More details here: http://board.flashkit.com/board/showpost.php?p=4198441&postcount=18 )

Anonymous said...

So true!

Chuck Vose said...

Just wondering if you've looked at the Key and KeyCombo classes from Casalib.ui.

CasalibDocs

3d animation courses said...

Hi why don't you give the details of KeyCombo classes to us?? I think it's not possible to include everything in one post that's why he might omited that but you can share about it with us.

Josh Tynjala said...

The stage cannot be a singleton because there can be more than one. In AIR, every window has a different stage. That's why they did it that way.

By the way, did you know that code in a constructor can be slower than other code? For whatever reason, it isn't JITed by the runtime, so it's actually better to move initialization code out of the constructor, even if you're just calling another function from the constructor. Weird, but true.