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);
}
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
firstChildandchildNodein 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 »