|
-
Complete Remake
Okay I have looked at your code, and your right about a re-hash :P
I have completely re-written your code.
I have kept your variable names though, as well as the list instance name.
Please read though the comments which are in the quotes thoughout the post as it will help explain what I have done, and help fix future issues for you.
This code will work, with the instance name of gen1List
Tested in Flash CS3, AS2.
I have re-written the xml as elements: My reasoning below
 Originally Posted by "Mr Wabbit
You should always avoid attributes issues with attributes are as follows:
> Attributes make the xml confusing, often causing mistakes. With Elements you can create easy to read trees.
> Attributes are not designed for easy expansion, with elements you can add as much information as you like.
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<links>
<item>
<label>001: Item One</label>
<url>http://www.my-eccomerce-site/item-1.html</url>
</item>
<item>
<label>002: Item Two</label>
<url>http://www.my-eccomerce-site/item-2.html</url>
</item>
<item>
<label>003: Item Three</label>
<url>http://www.my-eccomerce-site/item-3.html</url>
</item>
</links>
NB: To add another item to your list all you need to do is add another item with the label and url as shown above
The Action script is designed to check the number of item nodes you have in your xml, so will always call the correct amount.
On to the actionscript.
Again I have done a large amount of changes to your original actionscript.
 Originally Posted by "Mr Wabbit
> First I have moved the onLoad to a separate function: This is to create a easier to read and well layed out code.
> I have also added the else statement to the load function and well as a loaded variable
This will stop any errors with the infomation which is called.
Secondly, you will get a trace if the XML has failed to load, in which case check the url of the xml where xmlData.load (4th line)
> Fixed your checking of node lengths, you also had 2 loadXML functions which may cause a clash, where data is called twice.
> Added a single addItem instance, your lab and link vars will update with the firstChild.childNodes[i], again this helps for a nicer layout and smarted code
> OnRelease wont work with a class, (list class inc) you need to create a listener on your list class. The listen checks the list class at the frame rate. If you change selection it will get the url or the item in the list.
Code:
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xml/items.xml");
function loadXML(loaded) { //This way the functions only happen if the xml is loaded (loaded is our var)
if (loaded) { //If loaded
var nodes = xmlData.firstChild.childNodes;//Find the number of nodes to add
for (i=0; i<nodes.length; i++) {
_root.lab = this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
_root.link = this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
gen1List.addItem( {label:_root.lab, link:_root.link} );
}
} else {
trace("Your XML has not been loaded");
}
}
var listener:Object = new Object();
listener.change = function(evt) {
getURL(evt.target.selectedItem.link);
};
gen1List.addEventListener("change",listener);
Wow, that took me 30 mins to type up on here, and an hour to re-write and test :P
Lucky I had time, I did notice your post earlier though didn't have the time as knew it would take some time.
Remember to mark as resolved, and best of luck on your project.
Trust my code, and not my english.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|