|
||||||||||||||
. . . . . |
Tree Component and XML in Flash 8
This tutorial leads on from the basic mp3 player tutorial.
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com
<?xml version="1.0" encoding="iso-8859-1"?> <tree> <folder label="Pop Clips"> <video label="Britney Spears" url="crap.flv"/> <video label="Justin Timberlake" url="worsecrap.flv"/> <video label="Bland Bimbo" url="yuck.flv"/> </folder> <folder label="Cool Animation"> <video label="South Park" url="south.flv"/> <video label="Futurama" url="bender.flv"/> <video label="Drawn Together" url="bigbro.flv"/> <folder label="Canadian Anims"> <video label="Pit n Kantrop" url="pitt.flv"/> <video label="Qui es Moi?" url="que.flv"/> </folder> </folder> <folder label="Reality TV"> <video label="Big Brother" url="big.flv"/> <video label="Survivor" url="survive.flv"/> <video label="Wife Swap" url="biatch.flv"/> </folder> </tree>
That was your xml file to hold all the data for your playlist. Make sure that you save your xml file in the same folder as your videos and your flash file. Why did we use xml I hear you ask? Because we then do not have edit the flash 8 .fla file whenever the playlist changes. We just edit the xml text file. It is a good idea. Now where was I?
stop();
// create xml object
var xml:XML = new XML();
// ignore any white space
xml.ignoreWhite = true;
// onload xml function
xml.onLoad = function(){
// link tree to xml file database
myTree.dataProvider = this.firstChild;
}
// load xml file
xml.load("tree.xml");
// create obj for the tree listener
var treeListener:Object = new Object();
// event function for listener
treeListener.change = function(){
// what is clicked on in tree
var item = myTree.selectedItem;
// the url attribute of that item
var myurl = item.attributes.url;
// if there is an element
// and it is not a folder
if(myurl){
// play video for instance
// or play mp3
// or show a picture
trace("Selected: " + myurl);
}
}
// register listener with function and object
myTree.addEventListener("change", treeListener);
Do not just copy and paste the code and not take the time trying to understand the Actionscript involved. I have commented most of it , so play with it and try and break it and change things around so that you understand what is happening. Flash 8 Resources
basic mp3 player tutorial. . |
|
||||||||||||
|
. | Home | Flash MX | Actionscript 2.0 | Flash 3D | Flash 8 | Flash Database | Flash Mobile | Flash CS3 | Java For Kids | Video Course | General Video | Photoshop | Web Design | Digital Photography | Games | free backgrounds | Resume | Streaming Video | Students Work | Links | Contact me | sitemap | reviews | . . |
||||||||||||||