Simple XML to ActionScript 3 Menu

ActionScript 3 menu icon

This was my first attempt at an XML-driven menu in ActionScript 3, back in 2008 — one of the most-requested features of the era, since hard-coded menus meant recompiling the SWF every time a client wanted to rename an item. The sample files (with the .fla included) were downloaded from the link below; note that RapidShare, the file host used at the time, shut down in 2023, so the original download is gone. I’ve kept the post up because the code structure itself is still a good case study in decoupling data from presentation.

mainmenu display
The menu in action.

The core idea: drive the menu from XML

The design was deliberately simple: define the entire menu in an XML file, load it at runtime with URLLoader, parse it with ActionScript 3’s native XML class (E4X made this pleasantly terse), and build the menu from MovieClips. Changing the menu meant editing XML — no recompile, no ActionScript changes:

var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("menu.xml"));
loader.addEventListener(Event.COMPLETE, onMenuLoaded);

function onMenuLoaded(e:Event):void {
    var menuXML:XML = new XML(e.target.data);
    for each (var item:XML in menuXML.item) {
        var mc:MenuItem = new MenuItem();
        mc.label.text = item.@label;
        mc.target = item.@href;
        mc.addEventListener(MouseEvent.CLICK, onMenuItemClick);
        addChild(mc);
    }
}

This is the same pattern every menu system since has used — ASP.NET’s XML MenuDataSource, early jQuery plugins, and every modern CMS nav builder. Data drives structure; code renders it.

A note for anyone porting this

If you’re digging this up to migrate an old Flash site in 2026, the translation is usually mechanical: XML becomes JSON, URLLoader becomes fetch(), MovieClip hierarchies become DOM elements or React components, and the click handler becomes an event listener on the container. The menu logic above maps almost one-to-one.

Comments below are from 2008–2009 — including several people who couldn’t get the RapidShare download, which, given the host is now defunct, has aged into a joke at my expense.

8 thoughts on “Simple XML to ActionScript 3 Menu

  1. wonky says:

    Looks like it could be really good but it tells me there is an error with the location of the CallArg.as……
    I’ve tried changing its location and the Import location on the main fla but to no joy… 🙁

    I’ve been try to learn how to make an animated XML AS3 menu in for weeks now and just cant do it… or can I find a good tutorial…

    how did you learn how to do this???

    thanks in advance

    V

    Reply
  2. worthposting says:

    in any flash file you need to specify the your class directory

    CTRL + SHIFT + F12 (Publish Settings)

    Tab Flash
    Settings Button
    Enter the Class Path with (+) sign something like
    “[directory where .fla is located]\com\utils”

    in my case was:
    I:\flash\mainmenu\com\utils

    this CallArg.as is actually a good class that overrides the addEventListener handler so that you can pass extra custom values.

    Good practice examples are all over the net…. Keep searching. If you need anything else I m here.. :p

    Reply
  3. HSCharles says:

    I have a flash site
    i’m looking for the script who of google ads on flash.
    how can i get it?

    Reply
  4. Missvania says:

    Hi. I would like to get the file. But am unable to download it off rapid share. Is there any where else I can download that from?

    Or, can I trouble you to send me a copy of it?

    I need it urgently, I need to see how this is done and learn it. It would be a great help if I can get it.

    Thanks alot.

    Cheers,
    Vanessa

    Reply
  5. worthposting says:

    Missvania the link works ok (i checked it)… maybe you should check if you have a problem with rapidshare.

    Reply
  6. Missvania says:

    I think I do. I can never download from rapidshare Is there other options for me to download it?

    Thanks.

    Cheers,
    Vanessa

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *