Here’s some thoughts on Flash and the iPhone:
http://www.washingtonpost.com/wp-dyn/content/article/2010/01/10/AR2010011003065.html
Author: admin
unloadAndStop
Get rid of loaded assets when you’re done with them.
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/Loader.html#unloadAndStop%28%29
Note: This requires Flash Player 10.
SWF files loaded into Flash can sometimes still exist after they have been removed from the stage. The is cause by teh way Flash cleans up elements. If an element is referenced by another object Flash figures it’s still in use and should no be removed.
In some cases this can work to your advantage. Imagine you have a dialog box that appears on the stage periodically to set options in your application. You can remove it from the display list, and then add it to the display list at a later time and have it in tact with all of it’s elements in the same state.
In other cases this can be a problem. For example you load an swf and then you remove it from the stage, but it still takes up RAM and might even still be running it’s enter frame or other events in the background.In this case it’s hurting the efficiency of your application.
The unloadAndStop() method tries to solve this by stopping all actions running in a loaded element and clearing the element out of RAM. The unloadAndStop() methos belongs to the Loader class. The idea is to call this method on your Loader instance to clean what you have loaded.
Video tutorials
I posted a bunch of video tutorials here: http://www.screencast.com/users/webdevils# . This is a new site with more tutorials. The last site I used was Vimeo. Their site tended to resize the videos and put more restrictions on uploads. The new site doesn’t resize or recompress the videos so the quality us much better. They also support flv, which allowed me to upload some tutorials I had in this format.
These tutorials cover various aspects of Flash from beginning to more complex stuff.
I’m going to upload the example fla files to the google code site as soon as I get a chance.
target vs currentTraget
When working with MouseEvents the event object provides two properties that refer to object that originated the event: target and currentTarget. The right choice between these two is almost always currentTarget.
The problem with target is that often it is not the object that you think it is. The target property is the object that was actually clicked. This can any object nested within the MovieClip that was clicked, and often not the MovieClip itself, which is what you are most often expecting.
The currentTarget property on the other hand is the object that registered the event. Which is almost always what you are expecting.
So for general use it should always be currentTarget. The target property does provide an interesting function but in most cases it’s not what you think it is.
Good Habits:Variable Names
Writing your AS becomes easier if you develop a few good habits. Defining and naming variables is something you will find yourself doing often. Here some conventions that I always follow:
I always name private variables beginning with an underscore. For example:
private var _radius:Number;
I never define the value for a variable in the declaration. Instead I define initial values in the constructor of the class or a function that is called from the constructor. If I am passing an argument variable that will set the value of a class variable I use the same name, without the underscore. For example, the following defines a simple class with two private variables which are passed as arguments in the constructor:
package { import flash.display.*; public class Ball extends Sprite { private var _radius:Number; private var _color:uint; public function ball( radius:Number, color:uint ) { _radius = radius; _color = color; } } }
Here the class defines both _radius and _color. These are private so they begin with the underscore (_). They get their values from the two argument (or parameter) variable radius and color (note that these names lack the underscore). Then I set _radius = radius and _color = color in the constructor.
You can come up with your own system, this is what I use. Best is to have a system and use it the same way every time. I like this system because the naming system is very clear.
AS3 Jpeg encoder
Here’s a great article on making a Jpeg file from a movieclip with AS3.
http://henryjones.us/articles/using-the-as3-jpeg-encoder
Crayon Physics
Here’s a great game. I really want to play this. Too bad it’s only on Windows for the time being.
Here's a list Flash physics engines
Here’s a list and quick review of each of the popular Flash physics engines.
http://henryjones.us/articles/actionscript-3-physics-engines
Box2d
Yet another one! This looks like another good physics engine for Flash.
http://box2dflash.sourceforge.net/
Here’s a few video tutorials on using Box2d. These look pretty interesting. There are a lot I watched a few and got some good information.
FOAM
And another, physics engine. this one looks pretty good.
http://blog.generalrelativity.org/actionscript-30/foam-rigid-body-physics-engine-alpha-release-01/
After playing with FOAM for an evening, I found this engine to be a fairly easy to work with. I did run into a problem where the FOAM Vector class conflicted with the built in Flash Vector class. The Flash Vector class was added in CS4, FOAM obviously was written before this.
The problem could have been circumvented by carefully qualifying package names. This would have been an elegant and intelligent solution. In stead I decided for the more ham fisted approach of changing all instances of the name Vector to VectorPoint.
I just opened all of the files in the org.generalrelativity.foam and subpackages and did a find and replace on each file, replacing Vector for VectorPoint. Don’t forget to change the file name of Vector.as to VectorPoint.as. Compiler errors will often point out any spots where you missed an instance of the name.
The generalrelativity blog posts some FOAM renderers. This are useful files. I packaged them in the org.generalrealtivity.foam.view package. It seemed like a logical place to store them. Don’t forget to change the package declaration at the top of each of these files.
FOAM seems pretty easy to use. Unlike Box2d it uses pixels and stage coordinates to position elements on the stage which made it more intuitive to use. The property names seem very intuitive also. Moving objects look to all be built off the SimpleParticle class. Which has obvious properties like x and y to work with. So, creating any Object that inherits from SimpleParticle, you can position it by setting it’s x and y to stage coordinates. Pretty simple. Almost like working with regular MovieClips.
I did notice that fast moving objects could pass through another object. I assume this is caused when the velocity is great enough that the object moves past the interposing object without intersecting.