{"id":2008,"date":"2004-03-20T16:12:30","date_gmt":"2004-03-20T16:12:30","guid":{"rendered":"http:\/\/www.soulhuntre.com\/items\/date\/2004\/03\/20\/flash-based-xml-parsing\/"},"modified":"2004-03-20T16:12:30","modified_gmt":"2004-03-20T16:12:30","slug":"flash-based-xml-parsing","status":"publish","type":"post","link":"http:\/\/legacyiamsenseiken.local\/2004\/03\/20\/flash-based-xml-parsing\/","title":{"rendered":"Flash based XML parsing"},"content":{"rendered":"

ed note: I am writing this entry because it too me 12 hours or so to cram the solution to my current problem into my head. I am goign to nap. If I lose it all, this entry will give me the fast track on getting it back if I need it \ud83d\ude42<\/i><\/p>\n

Flash<\/a> and XML<\/a>, two things that should go together. So for the Client A site I have data in the CMS (content management system) and I need to use it to build submenu’s for navigation. No problem, I used a PHP script to pull it out and build an XML file. Pulling that into Flash is no problem… the thing is, what to do with it?<\/p>\n

To start with, I tied it into the nice components that come with Flask 2004 MX. I figure that’s what they are there for. And it works, the XML goes into a component and that gets wired to a list box and blammo<\/i>… it works. Except the list box looks nothing like I need it to for the client… and the one thing I need to be able to do (make the background transparent) doesn’t seem to be possible.<\/p>\n

<\/p>\n

Ok, backup plan. Put a bunch of label components in the menu area, stack ’em and handle the indexing for the scroll myself. I needed to do it anyway ’cause the scrolling wasn’t going to be standard. So I can’t use the auto XMLConnector, I have to use the regular XML stuff and walk the tree<\/a> myself.<\/p>\n

\n

Example 1<\/b><\/u><\/p>\n

<?xml version=”1.0″ ?>
    <galleries>
        <gallery>
            <title>Art Work<\/title>
            <id>2<\/id>
            <weight>25<\/weight>
            <url>\/content\/sections\/gallery\/gallery.php?gallery_id=2<\/url>
            <target \/>
        <\/gallery>
        <gallery>
            <title>Test gallery<\/title>
            <id>4<\/id>
            <weight>25<\/weight>
            <url>\/content\/sections\/gallery\/gallery.php?gallery_id=4<\/url>
        <target \/>
    <\/gallery>
<\/galleries><\/p>\n<\/blockquote>\n

So I spent a LONG time looking for a good tutorial on this stuff, and finally found a great tutorial<\/b><\/i> that made it all nice and clear<\/a>. Then I foudn out Flash is somewhat faster parsing attributes than it is parsing nodes. Now I tend to write node heavy XML (see the above example) but no problem, I re-wrote my PHP and came up with example 2. Don’t let the node name changes throw you, I also wound up making it more generic to the idea of a “menu” so I can re-use the parsing.<\/p>\n

\n

Example 2<\/b><\/u><\/p>\n

<?xml version=”1.0″ ?>
<menu>
    <item title=”Art Work” weight=”25″ url=”\/content\/sections\/gallery\/gallery.php?gallery_id=2″ target=”main_content” \/>
    <item title=”Test gallery” weight=”25″ url=”\/content\/sections\/gallery\/gallery.php?gallery_id=4″ target=”main_content” \/>
<\/menu><\/p>\n<\/blockquote>\n

 So there you have it. Make sure you read the tutorial<\/a>, but I copied the magic here (no, it doesn’t match the above XML, but it is a good template).<\/p>\n

\n

The Rosetta Stone of Flash\/XML for me…<\/b><\/u><\/p>\n

menuXml = new XML();
menuXml.ignoreWhite = true;
menuXml.onLoad = function(success) {
    if (success) {
        menuItem = this.firstChild.childNodes;
        for (var i=0; i<menuItem.length; i++) {
            item = _root.attachMovie(“itemClip”, “itemClip” + i, i);
            item._x = 0;
            item._y = 20*i;
            item.itemLabel.text = menuItem[i].attributes.name;
            item.myUrl = menuItem[i].attributes.url;
            item.onRelease = function() {
                getURL(this.myUrl,”_blank”);
            }
        }
    }
}
menuXml.load(“myMenu.xml”);<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

ed note: I am writing this entry because it too me 12 hours or so to cram the solution to my current problem into my head. I am goign to nap. If I lose it all, this entry will give me the fast track on getting it back if I need it \ud83d\ude42 Flash and […]<\/p>\n","protected":false},"author":3,"featured_media":53130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[278],"tags":[],"_links":{"self":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/2008"}],"collection":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/comments?post=2008"}],"version-history":[{"count":0,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/2008\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media\/53130"}],"wp:attachment":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media?parent=2008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/categories?post=2008"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/tags?post=2008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}