Brian Hadaway

Professionally Nerdy Since 2002

Loading XML with Namespaces in ActionScript 3

You might not appreciate how easy it is to load XML in ActionScript 3 if you never had the arduous task of loading it in AS2. It changed my life (at least my professional life) the day I learned that you no longer had to blindly dig through XML using terms like firstChild and childNode in order to get at the data you want. The use of E4X syntax in AS3 allows us to call nodes by name and drill right to the data we want, turning us all into external data pros.

All was good in the world of external XML data for me until the day I encountered XML that used a custom Namespace. I felt like I was thrown back to the days of AS2 where I couldn’t get to data in the XML no matter how hard I tried. I could load the data, but I couldn’t access it using E4X. Hopefully if you’re reading this you haven’t searched as long as I did for the answer. Here’s how you handle loading XML with a custom Namespace in Flash. Read More »

Posted in Flash | Tagged , | Leave a comment

Removing DisplayObjects In A Loop

This might be blatantly obvious to other Flash developers, but it took me a while to figure out so I’ve posted it here for posterity’s sake. I had some code that added several objects to the stage as such:

for (var i:uint = 0; i < 10; i++)
{
	var mc:MovieClip = new MovieClip();
	mc.graphics.beginFill(0xCCCCCC);
	mc.graphics.drawRect(0,0,50,50);
	mc.x = (i*52) + 15;
	mc.y = 175;

	var tf:TextField = new TextField();
	tf.text = String(i);
	mc.addChild(tf);

	addChild(mc);
}

Read More »

Posted in Flash | Tagged , | Leave a comment

Speed Up Your Workflow with the Gaia Flash Framework

I love the Gaia Framework for Adobe Flash! It’s an incredible tool that I wish I had known about when I was burning through development time on boring, low-level tasks like creating navigation and page transitions, preloading, asset management and dynamic font loading. Read More »

Posted in Flash | Tagged , , , | Leave a comment

Getting Started with Flash Webcam Motion Tracking

It seems that the subject of Flash motion tracking has been neglected as of late. Developers who want to develop something that looks cool and responds to motion have opted to play with FLARToolkit/Augmented Reality. The gesture recognition and multi-touch capabilities of Flash Player 10.1 provide a user interface that reliably captures user input better than the difference/threshold method of motion tracking in Flash. So will we ever have a Minority Report-style UI that allows us to fight crime by flailing our arms? If so, it probably won’t be built with Flash. But can we still create some stuff that looks cool using motion tracking in Flash? Absolutely. Read More »

Posted in Flash | Tagged , , , | 3 Comments

Real Erasing in Flash

I needed to make the drawing app for a client that allowed users to draw on top of an image and erase what they’ve drawn. Most drawing apps built in Flash allow users to erase, but they cheat by using a solid background and drawing the background color over the user’s drawing when the app is in “eraser” mode. That doesn’t work with a bitmap background.

Dead set on having the erase functionality, I set out to do what seemed to be impossible. After some research and quite a bit of trial and error, I found a solution. Using the BitmapData class’ threshold method, I could isolate drawn pixels in the eraser’s radius and set their alpha to transparent. It’s a little processor intensive but it fit the requirements of the project…almost. As it turns out, the client changed their mind about giving users the ability to erase. So this bit of code didn’t make the cut.

Posted in Labs | Comments closed

Audio Visualization

I decided to give the SoundMixer computeSpectrum method a once over and came up with some pretty cool animation. In this one, I attached movieclips at various points along the waveform then animated the movieclips. The computeSpectrum method does all the work and I get all the credit.

Posted in Labs | Comments closed

Audio Visualization 2

I decided to give the SoundMixer computeSpectrum method a once over and came up with some pretty cool animation. In this experiment, I converted the waveform by computeSpectrum to a circle and drew lines between the resulting points using the drawing API. I threw a filter on the drawing and scrolled it slightly. Take that Windows Media Player!

Posted in Labs | Comments closed

Dynamic Bézier Point

I needed a way to draw a Bézier curve between sets of points. It was necessary for the line to curve the same amount regardless of how far apart the points were. I also needed a way to animate the line as it was drawn. Using some geometry and adjusting for the orientation of the Flash Cartesian coordinate system, I devised a way to determine the Bézier point. Then I used Tweener to animate an invisible movieclip between the start and end point while curving to the Bézier point along the way. As Tweener updated, I used the drawing API to draw between the start point and the current position of the Tween.

Posted in Labs | Comments closed

Sound Generation

This experiment utilizes the sound generation capabilities of AS3. Sound is generated left to right based on the position of the sliders. The vertical position of the sliders determine the sound’s pitch while the horizontal distance between the sliders determine a tone’s duration. Adjust the sliders and hear what happens.

Posted in Labs | Comments closed

Pollock Generator

My friend Donnie has this Christmas tradition of donning a lamb’s wool vest, climbing into the hole that used to be a swimming pool in his parent’s back yard and making Jackson Pollock-esque paintings. While I’m sure I’ve seen similar holiday scenarios depicted on collectible Currier & Ives saucers, I’m pretty sure this isn’t normal. So I created this 100% ActionScript Random Pollock Generator for Donnie so that he can spend his Christmas vacation participating in more normal family traditions like knitting holiday-themed cat sweaters.

Posted in Labs | Comments closed