Accordion Meets XML

So a reader asked how to implement our accordion script using XML to populate it, and I think the results aren’t half bad. I’m not sure what he meant by a cervical shaped accordion though… Circular maybe? hopefully?

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

source files for the xml’d accordion

private function init()
	var request:URLRequest = new URLRequest("wp-content/xml/images.xml");
	loader = new URLLoader(request);
	loader.addEventListener(Event.COMPLETE, loadComplete);
private function loadComplete(evt:Event)
	data = XML(;
	accord = new accordion(500, 400, data.panel.length(), 20);
	for(var i:int=0; i < data.panel.length(); i++)
		var panel:MovieClip = new NavPanel(data.panel[i].name);
		var contents:MovieClip = new ImgHolder(data.panel[i].img);
		accord.addPanel(panel, contents);
<?xml version="1.0" encoding="UTF-8"?>
		<name>panel one</name>
		<name>panel zwei</name>
		<name>panel tre</name>
		<name>panel quattre</name>
  • Christopher Keeler

    Awesome component. I have managed to hack apart this to work with RTMP video streams. Just a few more problems to work out though, like only getting the video streams to play on the active panel.

    Currently thay all play at once…:(

  • nilloc

    Hey Christopher,
    There is an even being dispatched when each panel is opened. You could ( and i should, or will when i get a few spare minutes ) wait and do the load of the pic or video when the even it changed.

    //add this to the main function or perhaps an init function
    accord.addEventListener(accordion.EVENT_ON_CHANGE, somethingchanged);
    public function somethingchanged(evt:Event):void{
         trace("the panel changed to number "+accord.currpanel);

    I also would like to revisit the accordion events and include the actual panel in the event that is returned, to make it easier to add things too on the fly. But that wasn’t an original need for the code.

  • Christopher Keeler

    Not sure how to implement the event with netStream, or how to load the Video object with the selectedIndex? Any help would be great!

    Also…looking for a way to tint the gradient of the NavPanel via an XML hexedecimal value.


  • Christopher Keeler


    How do you access the Contents movieclips programatically? I am trying to invoke the method, but there are no instance names or identifiers.



  • Christopher Keeler

    Accordian Panels meet XML colors

    I modified the NavPanel class to be able to colorize the gradient of each accordian panel via an XML attribute. This also draws the panels with code, so you can customize the shape.

    import flash.display.*;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.text.TextFieldAutoSize;
    import flash.text.AntiAliasType;
    import flash.text.Font;
    import flash.geom.*;

    public class NavPanel extends MovieClip
    private var fmt:TextFormat;

    public function NavPanel(ttle:String, pnlColor:String):void
    var panelShape:Shape = new Shape();
    var matr:Matrix = new Matrix();
    matr.createGradientBox(100, 0, 0, -60, 0);‘linear’,[0xFFFFFF,pnlColor],[1,1],[0,255],matr);,300);,300);,256);,246);,236);,0);,0);;
    //Font Embedding
    var font:Font = new Arial();
    fmt = new TextFormat();
    fmt.bold = true;
    fmt.color =”0xFFFFFF”;
    fmt.size = 12;
    fmt.font = font.fontName;
    var title_txt:TextField = new TextField();
    title_txt.autoSize = TextFieldAutoSize.LEFT;
    //title_txt.defaultTextFormat = this.fmt;

    title_txt.text = ttle;
    title_txt.embedFonts = true;
    title_txt.selectable = false
    title_txt.rotation = 90;
    title_txt.x = 19;
    title_txt.y = 5;


  • Christopher Keeler

    XML attributes:
    vid url=”DCCTech” buttonText=”ABOUT THIS CENTER” button=”pnlAbout” color=”0x5A7851″ eventMarker=”28.5″ link=”aboutUs.cfm”

  • jeffdurand

    accordian.getPanelContentsAt(panelnumber) will give you the entire contents of the panel. Once you get the contents then you can inspect the contents for what you are looking for and call actions on it. Hopefully this helps. for instance you can look at the movie clip then recursively get get children till you find the correct object then simply call the method you want.

  • Christopher Keeler

    Sample of this accordion class modified to work with RTMP video streams from a Flash Media Server:

  • jeffdurand

    Wow christopher that is fucking tight man. I’m really happy you were able to figure out how to get the accordion class working with flashmediaserver. It looks really good and the streaming makes it ultra responsive. I’m going to be doing some stuff with red5 soon. I will likely post a lot of what I did you may find it useful if you want rtmp without the high cost of fms…. later jeff

  • Neil

    Really like using xml but having issues adding a swf into the xml. file. By the looks of it this is what you have done in the above ezample.

  • Michael Benin

    Thanks a bunch. Really a great help. Keep up the good work.