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.
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!
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.
Just clarifying an issue from last post: political rhetoric does not lead to violence like what happened. Violence that brutal comes from insanity and craziness. The proof is clear: someone who would shoot almost twenty people must be insane to do so. (Of course, this isn’t to say that they should not be held accountable for their actions.) Anyway, the point is this: horrid acts of violence come from insanity, not political rhetoric. Still, we should remember that rhetoric is what it is, and not get to upset over politics.
As I’ve watched all the horrific news this week, many will question gun laws in the US. Many people are unsure of how they fell about gun rights. A few points to establish first:
- Guns are not inherently bad
- Guns can be used for evil purposes
As a quick explanation, guns can be used for fine things, from hunting (although some may not feel this is so fine, within reason it is quite necessary) to recreation, or as a deterrent to crime (few will attack a guy carrying a firearm). The misuses of guns are quite clear already.
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.)