XML Menu

Hi all, just registered here cause I felt I needed some help with some actionscripting (Yes I am a noob but I’m ready to learn).

My teacher in Adobe Flash CS3 is so slow with the teaching (and some doesn’t understand what the .alpha = 0; does in my class so he has to teach them and they just keep us at thesame level). We has just taught my class “trace” (that’s hard… lol ^^).

Anyways, my problem is this:

I’ve made a XML file which gets loaded into Flash and it gets my animation and adds the labels to the buttons, so far so good, but I am trying to make these buttons do stuff when clicked, like (website menu) if you press “contact” it will show “contact” and if you press “home” it will go to “home” etc.

As I said I’m a bit of a noob to AS3 (started to go through it in class 2weeks ago, but as I said he teachs very slow we are better off on ourselves) so I’m not that sure off how to do this. before starting to talk what I’ve tried I’ll give out the code (it’s done after one tutorial with some modifications). Tutorial is found here: [URL=“http://tutorials.flashmymind.com/2009/02/creating-a-menu-via-xml/”]http://tutorials.flashmymind.com/2009/02/creating-a-menu-via-xml/

*XML File:

<?xml version="1.0" encoding="UTF-8"?>
    <links xpos="30" ypos="50">
        <link name="Home"        href="home" />
        <link name="Works"        href="works" />
        <link name="FAQ"        href="faq" />
        <link name="About"        href="about" />
        <link name="Contact"    href="contact" />

*AS file:

package {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.xml.*;
    import flash.text.TextFieldAutoSize;
     * ...
     * @ ...
    public class Main extends MovieClip {
        public var xmlPath:String = "Menu.xml";// XML file
        public var settingsXML:XML;    // Holds data of the XML file
        // Holds tweens so they don't get garbage collected
        public var tweensArray:Array = new Array();
        public var buttonTween:Tween;    // Tweens for the buttons
        public var loader = new URLLoader();
        public var xpos:Number;
        public var ypos:Number;

        public function Main():void {
            loader.load(new URLRequest(xmlPath)); // Loads xml file
            // When xml file is loaded, start function xmlLoaded
            loader.addEventListener(Event.COMPLETE, xmlLoaded);
        public function xmlLoaded(e:Event):void {
            // Makes you sure that you get values for the menu
            if ((e.target as URLLoader) != null) {
                settingsXML = new XML(loader.data);
                settingsXML.ignoreWhitespace = true;
                xpos = [email protected];
                ypos = [email protected];

                // Call function createMenu
        public function createMenu():void {
            // Represents a menu item
            var menuItem:MenuItem;

            var i:uint = 0;
            // Makes a new button/xml list file
            for each (var link:XML in settingsXML.links.link) {
                menuItem = new MenuItem();
                // Inserting menu labels
                menuItem.menuLabel.text = [email protected];
                // If label is longer than textfield, it will autosize
                menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;
                // Insert menu buttons to stage
                menuItem.x = xpos + i*110;
                menuItem.y = ypos;
                menuItem.alpha = 0.5;
                // Makes menuItems seen as buttons
                menuItem.buttonMode = true;
                menuItem.mouseChildren = false;
                // Add event listeners for the animations
                menuItem.addEventListener(MouseEvent.MOUSE_OVER, mouse_Over);
                menuItem.addEventListener(MouseEvent.MOUSE_OUT, mouse_Out);

                // Tells how many menu buttons we have
        public function mouse_Over(e:Event):void { // Menu button hoover effect
            buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, 1, 1.05, 1, true);
            buttonTween = new Tween(e.target, "alpha", Strong.easeOut, 1, .75, 1, true);
        public function mouse_Out(e:Event):void { // Menu button hoover-off effect
            buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, e.target.scaleX, 1, 1, true);
            buttonTween = new Tween(e.target, "alpha", Elastic.easeOut, e.target.alpha, 0.5, 1, true);


As you can see I’ve made a package of the actionscript (instead of writing it directly in Flash) and I’ve changed colours and such from the tutorial. ^^

So here’s what I tried:
I added a variable named “href” as the type of “String” in the main section. Then I added the line “href = link.@href;” into the for loop in function “createMenu”, then I added an event listener (under the MOUSE_OVER and MOUSE_OUT ones) that was a MouseEvent.MOUSE_DOWN. Then I added a function for it, and tried trace(href); but it only gave out the last inputed value for href from my XML file for every button.

How do I fix it? :3