Casting in Actionscript 3

I wanted to post something codey again, and this is a topic that can confuse some, so here we go.  This is actually a fairly broad topic, so I’m just going to cover some important things.

1. What is casting?
Casting is basically converting an object that is one type to another type.

2. Why do it?
There are numerous reasons – you’ll see them in the examples.  One main reason is that you have to sometimes.

3. How do you do it?
Good, on to the real meat.  There are to ways to explicitly cast (where you state it in your code) in ActionScript 3.  The first one is by  Type(myObject) .

var mySprite:Sprite = Sprite(randObject);

This takes a value of Type Number (5.5) and changes it to an integer, which is stored as myInt.

Continue reading

10 KB Nonogram Puzzle Game

Just released Nonogram Puzzlers, a flash game under 10 KB made in 10 days for a contest.  It’s a collection of 8 nonogram puzzles (also known as paint by number, griddler, or tsunami) made by me and one by a friend.  It also contains a user creation section.  It turned out well for the file size limit, I just didn’t get to polish it as much as I hoped because of the time constraints.  The actual solving interface turned out well, and is easy to use.  My biggest regret is that if you switch puzzles, your progress on your previous puzzle is erased.  Anyway, try it out and let me know what you think.  All are solvable by logic, except #9, which will probably take some guess and check.



Custom Cursors Demo in FP 10.2

You will need Flash Player 10.2 to view this!

Since FP10.2 is out, I thought I’d make a custom cursors demo. It relies on two outside libraries, MinimalComps and as3Gif. The project files are here! The demo demonstrates a static cursor, an animated one, and one you can draw in the program.

Continue reading

Vectors (ActionScript 3)

Many people still use Arrays when programming in Actionscript 3 when they should be using Vectors, so I’m going to give a brief synopsis of Vectors, especially their various constructors. Just as a warning, vectors are normally thought of as a math or geometric thing, a magnitude and direction. In Actionscript, they are not. If you are looking for this functionality either use Point for basic 2d stuff (or create your own Vector2D), or Vector3D for 3D geometric vectors. Why Flash named two totally different classes Vector and Vector3D is beyond me.

On to the Vector class in flash. A Vector is just a typed array – an array where all the objects in it are the same type. The benefits of using vectors include faster performance (major benefit) and not having to cast objects.

Continue reading

Colored Traces in FlashDevelop

FlashDevelop does a lot of cool things that make coding much easier. For example ctrl+shift+1 does everything from automatic variable and function declarations to auto-importing classes. Anyway, I came across a cool little trick recently by accident:

I was trying to distinguish between two booleans I was tracing so I added prefixes to tell which was which in trace:
When my second trace statement came out golden, I was quite surprised!

Continue reading

Flash Player 10.2 and Custom Cursors

About a month ago, Flash Player 10.2 was announced.  Lost in all the hoopla about the upcoming Flash Player 11 with low-level 3-D APIs and StageVideo of FP 10.2, was the introduction of custom cursors.  (Check out the docs here.) This should hopefully alleviate the pains of those who previously had to have an Mouse Move listener move a sprite to mouse coordinates, and will definitely provide a source of easy unlockables for games.

Continue reading

Text to Speech Fun

The possibilities for working with sound in ActionScript have been expanded with the relatively new SampleData event: you can now record sound from the microphone into a ByteArray or play sound dynamically from a ByteArray. This opens up the potential for all kinds of cool things, and I came across one example of this from Kelvin Luck, a class that plays back sounds at different speeds.

Also cool is the Google Translate text to speech webservice, which can be used to retrieve an mp3 file from a text query. Pete Shand circumvents the 100-character limit with his TextToSpeech class.

Combining these two I made a cool little application (just type in text, and press Hear):
Vodpod videos no longer available.


(If the swf doesn’t load, try here.)

Continue reading