How to Iterate The Properties of an AS3 Class

As you may have noticed, you can’t iterate over the properties of an Actionscript 3 class as if they were normal properties of a generic object, unless the class is dynamic of course.

here’s what I mean:

    public class Widget
        public var color:String = "green";
        public var shape:String = "round";
        public var age:String = "5";   

var widget:Widget = new Widget();

for(var i:String in widget)
    trace(i); // Whaaaaa? Output is blank! 

Ok, so as I said.. it doesn’t work. However, there’s trick that you can use! generate an XML list of the class variables, then access them as attributes (using the above example class):

var widget:Widget = new Widget();
var xmlList:XMLList = flash.utils.describeType(widget)..variable;

var vars:Object = new Object();

for (var n:int; n < xmlList.length(); n++)
    vars[xmlList[n]. @ name] = widget[xmlList[n]. @ name];

for (var prop:String in vars)
    trace(prop); // lists: age, color. shape

I took it one step further and pushed the variables into an object called vars so that I could show iterating it as an object.

This came in really handy for me earlier today. Maybe later I’ll elaborate, but I hope that you can see the value in being able to do something like this!

Super Fast: How to Add a Drop Shadow

Adding a dropshadow effect to a Display Object in Actionscript 3 is really easy. In Actionscript 3, Display Objects such as MovieClips have a property called filters.

To apply a drop shadow to your MovieClip, you must first import the DropShadowFilter. Then create a DropShadowFilter instance. Lastly, assign your new filter to the MovieClip’s filters property:

import flash.filters.DropShadowFilter;

var dropshadow:DropShadowFilter = new DropShadowFilter(15,45,10,0.5, 10.0, 10.0,1.0);
myDisplayObject.filters = [dropshadow];

I won’t get into the values passed to the DropShadowFilter constructor to make this short and sweet. If you would like to learn more about the particulars of this filter, see: Actionscript 3 Reference Manual

Adjust Global Sound Volume in Actionscript 3

There is a simple way to adjust all global sound in Actionscript 3. This encompasses all playing loops, sound effects and such.

All you need is the following code:


// volume limits are 0 to 1 (0.1,0.2,0.3,...,1)
SoundMixer.soundTransform = new SoundTransform(0);

Of course change the number sent to the SoundTransform constructor to anything between 0 and 1 (0.5 would be half max volume, 0 is muted.)

Find Hidden Malicious Code In Your Website

This is a little off the subject of Actionscript 3, but I think it’s an important little trick to know for anyone building content for the web. So here I am going to show a quick php snippet that will find hidden malicious code in your website, or more specifically, how to find hidden ‘strings’ of code in your site.

I’m not going to get into the obvious stuff about how to protect your site, site as good ftp passwords etc, that is for another article. This is just to help you find the offending garbage once it’s already there.

To cut to the chase, did you get some message while trying to visit your site saying that google has blocked it because of a virus infection? Usually it will give you a list of sites that are harboring malicious data that your site is linking back to. Someone has injected malware javascript into your site.

You can manually search for all of the infected javascript files, or you do the following:

1. create a new file, and call it finder.php
2. edit it, and paste the following code:

$input = "grep -r " . "'" . "keyword" . "'" . " *";
echo "Below is a list of all files containing your keyword:";
$output = shell_exec($input);
echo "<pre>#$output</pre>";

3. change the word keyword to the malware domain name that google reported your site to be infected with.
4. save this file into the root folder of your website.
5. navigate to

A list of occurences of that keyword will be shown. Now just open up all of the listed javascript files, scroll to the bottom and delete the code that has been injected into your site!

It will look through your entire site and return any instances of

Site optimized for non-IE browsers

I just wanted to leave a little note to let everyone know that this site is optimized for browsers that are NOT Internet Explorer. If you are using IE and notice weird things happening on my blog, well, they will not be fixed.

Internet Explorer Troll
IE Troll

I spend a GREAT deal of my working days hacking css on other sites that I work on for my day job in order to make them compatible with IE. I refuse to do this with my own site. If (however) you find problems with funky things happening in standards compliant browsers such as Firefox, Chrome or Safari, then I will be happy to look in to it.

Thanks, and most importantly – IE Sucks. Install a modern browser (Internet Explorer 9 does NOT count)!