ActionScript
AS3 DisplayObject Auto Depth Sorter
3A common issue I have while creating Flash/ActionScript 3 games is needing to depth sort DisplayObjects based on some property of the display object itself (most often, their y coordinate). I do this so often that, a while back, I created a special class that extends Sprite and automatically handles this for you. I thought it was finally time to share this handy utility class with the world, so here it is.
Example:
For an example, check out the Kung Fu Panda Tales of Po game I worked on. When the characters pass by each other across the “y” plane, they are automatically depth sorted without any extra coding work on my part.
Usage:
var mcContainer:SpriteAutoSorter = new SpriteAutoSorter(); mcContainer.sPropertyToSortOn = "y"; // "y" is actually used by default so this line is not necessary mcContainer.beginSorting();
And that’s it! Now just addChild and removeChild like normal and everything will be handled for you. To save on performance, you should call stopSorting() when it is no longer required. Enjoy!
Flash Game: Kung Fu Panda Tales of Po
2At Seven2, I served as the lead developer on the pilot game for a brand new Nickelodeon tv series based on Kung Fu Panda! This recently released game, called called Tales of Po, is in the running to be Nickelodeon’s 2011 Game of the Year (along with Voltron Ultimate Victory, another game that I served as lead dev on)! It’s a side-scrolling rpg-brawler with similarities to Double Dragon, Castle Crashers, etc. Stay tuned for future posts on some of they key development issues & solutions encountered while developing this game. In the mean time, go play it!
First Think Labs class starts tonight
0The company I work for, Seven2, along with its sister company, 14Four, or co-sponsoring Think Labs. Think Labs is a series of free classroom training sessions in online and mobile development. For years we’ve been putting our new employees through a rigorous training program and we’ve decided to share this training with the community. We had a large number of talented creatives apply, but only 10 spots were available. Narrowing it down was difficult! So I wanted to first say congratulations to the 10 all-stars that made the cut:
- Carlos Rivera
- Eli Snavely
- Ginny Baxter
- Jame Stinehart
- Karli Ingersoll
- Manny Trembley
- Mitch Rickman
- Nicholas Malara
- Peter Jantz
- Tyreil Poosri
The first session is an 8-week series dedicated to ActionScript 3.0 programming and it starts tonight! I’ll be co-teaching this course along with my adept partner-in-crime, Kipp Ashford.
If you didn’t make the cut this time around, stay tuned to the blog or the facebook page and we’ll let you know when the next session begins!
Flash bug: G KeyCode mysteriously different on key down vs key up
0I was making a Flash game that required the “G” keyboard key today. It listens for the KEY_DOWN event, stores that this key is currently down in an array indexed by they G keyCode, and then looks for the same array index when a KEY_UP event occurs.
The problem is, it’s not the same keyCode. Every other key on my keyboard traces the same uint for both KEY_DOWN and KEY_UP, but the G key, traces 71 for key down, and 144 for key up.
Don’t believe me? Try it for yourself. Here’s the code:
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler, false, 0, true);
this.stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler, false, 0, true);
function keyDownHandler($e:KeyboardEvent):void
{
trace("\nkeyDownHandler() $e.keyCode:"+$e.keyCode+"");
}
function keyUpHandler($e:KeyboardEvent):void
{
trace("> keyUpHandler() $e.keyCode:"+$e.keyCode+"");
}
Update 1: Apparently this only happens when compiling in Flash CS5. If you re-run the swf after compiling it in the debug player, 71 is properly traced both times. Still a bug, but not as severe.
Update 2: Valerio Virgillito, a Flash Professional Sr. Quality Engineer for Adobe, has verified that “This is a known issue on Mac. It’s a player bug and has nothing to do with Flash CS5… we have an internal bug filed for [it]. Once it’s fixed for the player the changes will trickle down to authplay”
I filed a bug report, which you can see and vote for here:
https://bugs.adobe.com/jira/browse/ASL-154
iPhone development in Flash CS5 Beta (link dump)
1[In light of recent events, I thought this worth reposting]
It took some digging for me to find all of the resources available on the subject so far, so I thought I’d share what I found:
Designing Flash Applications for iPhone, Arno Gourdol (MAX, 2009)
Source to 4 Flash iPhone apps, Ted Patrick
Building iPhone Applications with Flash CS5, Mike Chambers (FITC Edmonton, 2009)
Flash CS5 multi-touch (with source & video), Lee Brimelow
Flash Player 10.1 multi-touch FAQ, Lee Brimelow
Multitouch and the Flash Platform, Daniel Dura, Matt Bugbee (Max 2009)
Preparing for Multi-touch in Flash (including some 10.1 API’s), Kevin Suttle
Designing and Developing for the Multiscreen web, Thibault Imbert (Max 2009)
Flash CS5 iPhone FAQ, Lee Brimelow
Example iPhone apps built with Flash CS5, Adobe TV
Example iPhone apps built with Flash CS5, Adobe Labs
iPhone Geolocation AS3 API, Mark Doherty
Applications for iPhone:Developer FAQ, Adobe Labs
Developing for the Apple iPhone using Flash, Aditya Bansod
Building Applications for iPhone w/ Flash Pro CS5, Aditya Bansod (Adobe TV)
Optimizing Flash Content for iPhone Applications, Scott Peterson & Chris Brichford (MAX 2009)
Adobe’s Flash CS5 iPhone forums, Adobe
Flash to iPhone, Veronique Brossier
Flash on iPhone: My Experience, Ben Garney
Using a Mac? Check out these must-have Quick Look plugins
2It has been about year since I switched from Windows to Mac and I thought I would release a series of articles that discusses my workflow and the vital tools that I have discovered along the way.
Today, we talk about one of the best features of Apple’s OS: Quick Look. Highlight any file, press the spacebar, and instant preview! The lack of this feature is my biggest complaint whenever I switch back to a Windows OS. Unfortunately, there are a few file types that are either not supported, or else not supported as well as they could be. Enter Quicklook Plugins.
First off, here’s how to install them:
http://www.quicklookplugins.com/how-to-install/
And here are my favorite plugins:
- .as files using QLEnscript.qlgenerator
- .xml files with coloring using colorxml.qlgenerator
- .zip, .tar, .targz, .7z and others using Archive.qlgenerator
- .flv files using flv.qlgenerator (requires the free Perian component to be installed)
Resizing a Parent Sprite Without Resizing the Child Sprite
0A co-worker approached me with a problem today. He wanted to resize a parent Sprite (or MovieClip, DisplayObject, etc) without resizing the child Sprite. So, in a nutshell, here’s how you do it:
[ActionScript]
_mcParent._mcChild.scaleX = 1 / _mcParent.scaleX;
_mcParent._mcChild.scaleY = 1 / _mcParent.scaleY;
_mcParent._mcChild.x = _nChildStartX / _mcParent.scaleX;
_mcParent._mcChild.y = _nChildStartY / _mcParent.scaleY;
[/ActionScript]
And here’s a simple demo to illustrate the problem and the solution:
Flashplayer and AIR Benchmark Test app
2I’m currently using the Flashplayer in more of an embedded system configuration. We’re evaluating multiple hardware configurations to decide what hardware to use and we’re also evaluating multiple version of the Flashplayer to decide which Flashplayer to use. So I made a quick open source test app to help with this evaluation. It allows you to compare animation performance between an EnterFrame animation vs a Tweener animation vs a Timeline animation. You can also apply various effects to see how they impact things. Since scaling can skew results, the app is designed to run at a specific resolution, but it is easily scalable to whatever resolution you wish to test (and steps are included in the source).
The results have been rather bewildering at times. Depending on the hardware (and I think the OS as well), I have seen filter effects drastically decrease the performance, drastically increase the performance, I have seen full screen mode have great impact or no impact, I have seen the AIR version help the performance and hurt the performance, and just about everything inbetween. Crazy! Anyway, tell me what your hardware/OS/Flashplayer version combination are, and what sort of results you get in the comments.
Usage:
It should be fairly straight forward. Just drag the sliders to add a new ball that is animated in the specified method. You can click on the top half or bottom half of the DiagnosticStats window (thanks Mr. Doob!) to increase or decrease the max fps. Use the + or – keys to increase/decrease the maximum # of balls allowed. In the AIR version, press Q or X to quit and click and drag the background to move it around.
Demo | Source | AIR | AIR Source
Should Adobe follow the new ECMAScript 3.1 standard?
1For background, read:
- Standards, ECMAScript and representing the past
- ActionScript 3 and ECMAScript 4
- Ru Roh! Adobe Screwed By EcmaScript Standards Agreement
- How will ECMAScript “Harmony” affect ActionScript 3?
Keith Peters just posed a good question, Why Standards?. On the one hand, standards are undeniably good, assuming that the point of a “standard” is that many adhere to it. It’s pointless to call something a standard if you are the only one following it. For example, take the metric system vs the english system of measurement. There are really only two standards and it still causes us problems. Remember the $125 million lost Mars Climate Orbiter in 1999 because someone didn’t convert from one standard to another? Or closer to home, remember the problems of figuring out why your page looked one way in IE, another in Netscape, and another in Safari? The same page could look drastically different. Or how about the standard of XML? What a fantastic concept! I love that I can import an Excel file directly into Flash if I want to thanks to XML, or that I can interface with an app written in an entirely different language over Ethernet because it talks XML. It’s undeniable that standards can be very powerful.
However, it’s also undeniable that not everything should follow a standard. How boring it would be if everyone’s web page had to use the exact same look and feel and no one was allowed to use anything but text. This is, of course, ridiculous. Standards can be very powerful, but they can also be very inhibiting.
So the real question is not, “why standards?”, but rather, “should Adobe follow the new ECMAScript 3.1 standard?”
The only time I ever wish that various rich oop languages were more “standardized” is when one language has a really nice feature/ability that I become dependent on, and then I switch to another rich oop language that doesn’t support it. For example, there are many times that I have griped that I wish AS supported all of the features that usually come “standard” in other rich oop languages, such as private constructors, function overloading, strongly typed arrays (vectors), etc. ActionScript 3 was a big step in the right direction and I thought ES4 would solve most of my remaining gripes.
My view, however, implies that a standard in the programming world is used to set the *minimum* feature set that a language has, NOT the maximum. I agree with Keith Peters, that my employer and my personal career as a developer are both completely unaffected whether AS follows a named standard or not. On the contrary, I feel like AS currently *is* the standard, and undeniably so in the current RIA world. I believe Adobe should consider the ES3.1 standard and follow it where it makes sense, but I strongly believe it should ignore it altogether when it’s not in the best interest of the language or the community. Again, if MS, Apple, and Mozilla all decided that their browsers would support text only to be more standard with each other, everyone would jump ship in a heart beat to a “less standard” web browser that pushed the technology limit and supported images, video, sound, etc.
I believe Adobe has been pushing this technology limit for the last decade, and that they should continue to do so without consideration of slowing down in order to be able to claim that they are “compliant”.
Oh, and since we’re no longer worried about being compliant, can we please have private constructors back and true support for function overloading?
We’re Hiring: ActionScript 3 Engineer
0Well, we’re basically always hiring (so apply even if this ad goes away), but given that the OSFlash Job Board just had a relaunch, we thought we’d try our luck at using it.
Here’s the contents of the job posting:
ActionScript 3 Engineer
DigiDeal Corporation, Spokane Valley, WA
Deal yourself a winning hand! Join DigiDeal and develop digital games for the gaming industry! DigiDeal is the worldwide leader in electronic table game development. Our Digital Table System and game portfolio are recognized around the world for engineering excellence and innovation. We offer fully paid benefits, matching 401k plan, and competitive salary/incentives. DigiDeal is an EOE. If you’ve got what it takes, get in the game and work with the most creative and dynamic casino game developers.
DETAILS
-Develop multi-player Flash-based games
-Write Flash apps for touch screen technology
-Code exclusively with ActionScript3
-Join a team that is always trying to push Flash to its limits!
REQUIREMENTS
-3+ years software development
-BS/MS in CS or equivalent experience
-ActionScript 3 (preferred), AS2, Java, or C++
-Strong OOP skills is a must
-Game development is a plus
You can also apply be e-mailing me directly: natejc at this domain name dot com.
Adobe MAKE SOME NOISE
2I was also having problems with the SOUND_COMPLETE event. I discovered Andre Michelle‘s post petition about it and promptly added my name to the list. There have been multiple other people posting about the problem also. Unfortunately, the only response that I could find from Adobe was by Brent Baker on a bug report for the issue that states:
“FlashPlayer issues should be reported here. Also you will need to provide much more information on the issue: http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform”
It seems that the bug was closed without actually looking into it. Bummer.
Automatic Flash X,Y Wireframe Preview
0At the company I work for we use Functional Specification documents for any new Flash game that we make. Before any of the developers start any coding, the design team puts together a simple frame by frame Flash file to make it easy to see what things will look like in the various states of the game. This will eventually become screen shots put into the spec. There will be an additional section put into the spec that includes all of the top-left and center x,y coordinates for each MovieClip on the stage during each frame. That was usually a tedious part of the job that none of the designers liked doing. When they brought this to my attention, I decided to make a quick script to do this for them. Here are the results:
USAGE:
- Copy and paste the code into frame 1 of any Flash file
- Make sure all objects that you want wireframes for are Symbols (for some reason, the x,y is off if they aren’t)
- Run the swf
- Use the arrows keys to change frames
- Use space bar to toggle wireframe view
- You may press the space bar multiple times to get new random colors
- You can click and drag on the x,y text to move it to a new location
SAMPLE:
mouseEnabled and mouseChildren Affect CPU Load
4I was reading a post from Keith Peters today and noticed a comment made by Ryan Taylor mentioning that mouseEnabled and mouseChildren affect the CPU load. I had to know if this was true or not so I promptly created an experiment app. The app randomly creates 700 parent sprites and 700 nested children sprites. You press the SPACE bar to toggle .mouseEnabled and .mouseChildren for all of the objects.
I couldn’t believe it. Although disabling these properties did not seem to affect the FPS, it definitely affected my CPU. When tested on my WinXP,SP2 machine with a P4 3.4 HT CPU, the swf was taking 13-16% of my CPU. When I set mouseEnabled and mouseChildren = false, the CPU load dropped to 4-6% total! It cut down the CPU usage by about 300%! Very good to know. Thanks for the tip Ryan!
Particle System, v0.1
3I have seen many particle systems released on many different blogs. I’ve always thought that they were pretty cool and I’ve thought multiple times about making one myself, but decided not to for the single reason that I didn’t want to be just the next guy to jump on the bandwagon of things that have already been done. But, after seeing Seb Lee-Delisle’s presentation on particle systems at Flash on the Beach ’07, I became a little more interested in doing it. Then, at the end of Robert Hodgin’s extremely cool presentation about processing, he left us with one simple image:

I don’t want to make the same crap that everyone else has been making, but I feel like you need somewhere to start. If a particle system was a good enough starting spot for Hodgin, it is for me to. So, on the plane ride home yesterday, I made my particle system from scratch. I didn’t want to look at anyone else’s code or algorithms, for better or worse, I just wanted to go for it. So, this may or may not be the most efficient way to do it, but here it is:
More work on this to come in the near future…








