PDA

View Full Version : Need as3 help



freshflashlearn
July 17th, 2009, 03:03 PM
some one explain what is the meaning of this code this code is for xml menu
i have bold and underline the code that i don't understand
there are three lines which i have bold and underlined

Final Code

//Imports needed for animation
import fl.transitions.Tween;
import fl.transitions.easing.*;

//XML file path
//You can use the following path as well if you want...
var xmlPath:String = "http://flashmymind.com/SWF/site.xml";

//The XML data will be inserted into this variable
var settingsXML:XML;

//Array used for the tween so they won't get garbage collected
var tweensArray:Array = new Array();
//Used later when we animate the buttons
var buttonTween:Tween;

// Load the XML file
var loader = new URLLoader();
loader.load (new URLRequest(xmlPath));
loader.addEventListener (Event.COMPLETE, xmlLoaded);

//This function is called when the XML file is loaded
function xmlLoaded (e:Event):void {

//Make sure we're not working with a null loader
if ((e.target as URLLoader) != null ) {
//Insert the loaded data to our XML variable
settingsXML = new XML(loader.data);
settingsXML.ignoreWhitespace = true;
//Call the function that creates the whole menu
createMenu ();
}

}

function createMenu ():void {
//This will be used to represent a menu item
var menuItem:MenuItem;
//Counter
var i:uint = 0;

//Loop through the links found in the XML file
for each (var link:XML in settingsXML.links.link) {

menuItem = new MenuItem();

//Insert the menu text (link.@name reads the link's "name" attribute)
menuItem.menuLabel.text = link.@name;

//If the text is longer than the textfield, autosize so that the text is
//treated as left-justified text
menuItem.menuLabel.autoSize = TextFieldAutoSize.LEFT;

//Insert the menu button to stage
menuItem.x = 20;
menuItem.y = 30 + i*40;

//Make the button look like a button (hand cursor)
menuItem.buttonMode = true;
menuItem.mouseChildren = false;

//Add event handlers (used for animating the buttons)
menuItem.addEventListener (MouseEvent.MOUSE_OVER, mouseOverHandler);
menuItem.addEventListener (MouseEvent.MOUSE_OUT, mouseOutHandler);

addChild (menuItem);

//Increment the menu button counter, so we know how many buttons there are
i++;
}
}

//Function is called when the mouse is over a menu button
function mouseOverHandler (e:Event):void {

//Double the width
buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, 1, 2, 1, true);
}

//Function is called when the mouse moves out from the menu button
function mouseOutHandler (e:Event):void {

//Tween back original scale
buttonTween = new Tween(e.target, "scaleX", Elastic.easeOut, e.target.scaleX, 1, 1, true);

}

This is the tutorial link
http://tutorials.flashmymind.com/2009/02/creating-a-menu-via-xml/