PDA

View Full Version : Tree component with XML


deepglue
06-10-2005, 07:08 AM
I've been trying to figure this out for past 2 days and can't find a single tutorial or example anywhere. Hopefully someone here can help!

Here's my code:

myTreeDP = new XML();
myTreeDP.ignoreWhite = true;
myTreeDP.load("categories.xml");
myTreeDP.onLoad = function() {
myTree.dataProvider = myTreeDP;
};
myTreeListener = new Object();
myTreeListener.change = function(evt:Object) {
url = evt.target.selectedNode.data;
MC_blank.loadMovie(url);
};
myTree.addEventListener("change", myTreeListener);


What I'm trying to do is play an external .swf (defined in "data" attribute in XML file) inside an empty movieclip when the user clicks on a LEAF node. With the code above (which I found somewhere) the movie attempts to play when user clicks on ANY node, but that's not what I need. I figure this should be pretty simple but I'm not very familiar with AS.

I'm about to go nuts.

Thanks in advance for any help!

Billystyx
06-10-2005, 01:42 PM
what's your XML doc look like?

There is an example here - at http://www.billystyx.co.uk, under tutorials/menubars of xml docs (but for menubars/,menus rather than trees)
(right at the bottom), in the listener though, you need to specify exactly which event object you want for certain things to happen - so use a switch statement.

(Also included in above link)

billystyx

deepglue
06-10-2005, 03:55 PM
Thanks for the link. Here's the XML code:

<node label="Ambient" value="1">
<node label="ambient 1" data="ambient1.swf" />
<node label="ambient 2" data="ambient2.swf" />
<node label="ambient 3" data="ambient3.swf" />
<node label="ambient 4" data="ambient4.swf" />
</node>
<node label="Rock" value="1">
<node label="rock 1" data="rock1.swf" />
<node label="rock 2" data="rock2.swf" />
<node label="rock 3" data="rock3.swf" />
<node label="rock 4" data="rock4.swf" />
</node>

Basically the tree needs to be populated with this XML data (which works) but when user clicks on a node labeled "ambient 2" for example, an external movie "ambient2.swf" would start playing. But the click is detected even when you click on parent nodes labeled "Ambient" or "Rock". I'm using external XML because new movies will be added frequently.