# Need as3 help

**URL:** <https://forum.kirupa.com/t/need-as3-help/292708>\
**Category:** Uncategorized\
**Created:** [July 17, 2009, 7:03pm UTC](https://forum.kirupa.com/t/need-as3-help/292708 "2009-07-17T19:03:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![freshflashlearn](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@freshflashlearn](https://forum.kirupa.com/u/freshflashlearn)\
**Post date:** [July 17, 2009, 7:03pm UTC](https://forum.kirupa.com/t/need-as3-help/292708/1 "2009-07-17T19:03:19Z")

</div>

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 \*\*

[COLOR=#808080]_//Imports needed for animation_[/COLOR]  
[COLOR=#0066CC]import[/COLOR] fl.[COLOR=#006600]transitions[/COLOR].[COLOR=#006600]Tween[/COLOR];  
[COLOR=#0066CC]import[/COLOR] fl.[COLOR=#006600]transitions[/COLOR].[COLOR=#006600]easing[/COLOR].[COLOR=#66CC66]\*[/COLOR];

[COLOR=#808080]_//XML file path_[/COLOR]  
[COLOR=#808080]_//You can use the following path as well if you want…_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] xmlPath:[COLOR=#0066CC]String[/COLOR] = [COLOR=#FF0000]“[http://flashmymind.com/SWF/site.xml](http://flashmymind.com/SWF/site.xml)”[/COLOR];

[COLOR=#808080]_//The XML data will be inserted into this variable_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] settingsXML:[COLOR=#0066CC]XML[/COLOR];

[COLOR=#808080]_//Array used for the tween so they won’t get garbage collected_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] tweensArray:[COLOR=#0066CC]Array[/COLOR] = [COLOR=#000000] **new** [/COLOR] [COLOR=#0066CC]Array[/COLOR]COLOR=#66CC66[/COLOR];  
[COLOR=#808080]_//Used later when we animate the buttons_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] buttonTween:Tween;

[COLOR=#808080]_// Load the XML file_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] loader = [COLOR=#000000] **new** [/COLOR] URLLoaderCOLOR=#66CC66[/COLOR];  
loader.[COLOR=#0066CC]load[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#000000] **new** [/COLOR] URLRequestCOLOR=#66CC66[/COLOR][COLOR=#66CC66])[/COLOR];  
loader.[COLOR=#006600]addEventListener[/COLOR] [COLOR=#66CC66]([/COLOR]Event.[COLOR=#006600]COMPLETE[/COLOR], xmlLoaded[COLOR=#66CC66])[/COLOR];

[COLOR=#808080]_//This function is called when the XML file is loaded_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] xmlLoaded COLOR=#66CC66[/COLOR]:[COLOR=#0066CC]void[/COLOR] [COLOR=#66CC66]{[/COLOR]

```
[COLOR=#808080]*//Make sure we're not working with a null loader*[/COLOR]
[COLOR=#B1B100]if[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#66CC66]([/COLOR][COLOR=#0066CC]e[/COLOR].[COLOR=#0066CC]target[/COLOR] as URLLoader[COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]![/COLOR]= [COLOR=#000000] **null** [/COLOR] [COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR]
	[COLOR=#808080]*//Insert the loaded data to our XML variable*[/COLOR]
	settingsXML = [COLOR=#000000] **new** [/COLOR] [COLOR=#0066CC]XML[/COLOR][COLOR=#66CC66]([/COLOR]loader.[COLOR=#0066CC]data[/COLOR][COLOR=#66CC66])[/COLOR];
	settingsXML.[COLOR=#006600]ignoreWhitespace[/COLOR] = [COLOR=#000000] **true** [/COLOR];
	[COLOR=#808080]*//Call the function that creates the whole menu*[/COLOR]
	createMenu [COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];
[COLOR=#66CC66]}[/COLOR]

```

[COLOR=#66CC66]}[/COLOR]

[COLOR=#000000] **function** [/COLOR] createMenu COLOR=#66CC66[/COLOR]:[COLOR=#0066CC]void[/COLOR] [COLOR=#66CC66]{[/COLOR]  
[COLOR=#808080]_//This will be used to represent a menu item_[/COLOR]  
**_[COLOR=#000000]var[/COLOR] menuItem:MenuItem;_**  
[COLOR=#808080]_//Counter_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] i:uint = [COLOR=#CC66CC]0[/COLOR];

```
[COLOR=#808080]*//Loop through the links found in the XML file*[/COLOR]
[COLOR=#B1B100]for[/COLOR] each [COLOR=#66CC66]([/COLOR][COLOR=#000000] **var** [/COLOR] link:[COLOR=#0066CC]XML[/COLOR] [COLOR=#B1B100]in[/COLOR] settingsXML.[COLOR=#006600]links[/COLOR].[COLOR=#006600]link[/COLOR][COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR]

	[U]**menuItem = [COLOR=#000000]**new**[/COLOR] MenuItem[COLOR=#66CC66]([/COLOR][COLOR=#66CC66])[/COLOR];**[/U]

	[COLOR=#808080]*//Insert the menu text (link.@name reads the link's "name" attribute)*[/COLOR]
	menuItem.[COLOR=#006600]menuLabel[/COLOR].[COLOR=#0066CC]text[/COLOR] = link.[COLOR=#66CC66]@[/COLOR][COLOR=#0066CC]name[/COLOR];

	[COLOR=#808080]*//If the text is longer than the textfield, autosize so that the text is *[/COLOR]
	[COLOR=#808080]*//treated as left-justified text*[/COLOR]
	menuItem.[COLOR=#006600]menuLabel[/COLOR].[COLOR=#0066CC]autoSize[/COLOR] = TextFieldAutoSize.[COLOR=#0066CC]LEFT[/COLOR];

	[COLOR=#808080]*//Insert the menu button to stage*[/COLOR]
	menuItem.[COLOR=#006600]x[/COLOR] = [COLOR=#CC66CC]20[/COLOR];
	[U]**menuItem.[COLOR=#006600]y[/COLOR] = [COLOR=#CC66CC]30[/COLOR] + i[COLOR=#66CC66]*[/COLOR][COLOR=#CC66CC]40[/COLOR];**[/U]

	[COLOR=#808080]*//Make the button look like a button (hand cursor)*[/COLOR]
	menuItem.[COLOR=#006600]buttonMode[/COLOR] = [COLOR=#000000] **true** [/COLOR];
	menuItem.[COLOR=#006600]mouseChildren[/COLOR] = [COLOR=#000000] **false** [/COLOR];

	[COLOR=#808080]*//Add event handlers (used for animating the buttons)*[/COLOR]
	menuItem.[COLOR=#006600]addEventListener[/COLOR] [COLOR=#66CC66]([/COLOR]MouseEvent.[COLOR=#006600]MOUSE_OVER[/COLOR], mouseOverHandler[COLOR=#66CC66])[/COLOR];
	menuItem.[COLOR=#006600]addEventListener[/COLOR] [COLOR=#66CC66]([/COLOR]MouseEvent.[COLOR=#006600]MOUSE_OUT[/COLOR], mouseOutHandler[COLOR=#66CC66])[/COLOR];

	addChild [COLOR=#66CC66]([/COLOR]menuItem[COLOR=#66CC66])[/COLOR];

	[COLOR=#808080]*//Increment the menu button counter, so we know how many buttons there are*[/COLOR]
	i++;
[COLOR=#66CC66]}[/COLOR]

```

[COLOR=#66CC66]}[/COLOR]

[COLOR=#808080]_//Function is called when the mouse is over a menu button_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] mouseOverHandler COLOR=#66CC66[/COLOR]:[COLOR=#0066CC]void[/COLOR] [COLOR=#66CC66]{[/COLOR]

```
[COLOR=#808080]*//Double the width*[/COLOR]
buttonTween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#66CC66]([/COLOR][COLOR=#0066CC]e[/COLOR].[COLOR=#0066CC]target[/COLOR], [COLOR=#FF0000]"scaleX"[/COLOR], Elastic.[COLOR=#006600]easeOut[/COLOR], [COLOR=#CC66CC]1[/COLOR], [COLOR=#CC66CC]2[/COLOR], [COLOR=#CC66CC]1[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#66CC66])[/COLOR];	

```

[COLOR=#66CC66]}[/COLOR]

[COLOR=#808080]_//Function is called when the mouse moves out from the menu button_[/COLOR]  
[COLOR=#000000] **function** [/COLOR] mouseOutHandler COLOR=#66CC66[/COLOR]:[COLOR=#0066CC]void[/COLOR] [COLOR=#66CC66]{[/COLOR]

```
[COLOR=#808080]*//Tween back original scale*[/COLOR]
 buttonTween = [COLOR=#000000] **new** [/COLOR] Tween[COLOR=#66CC66]([/COLOR][COLOR=#0066CC]e[/COLOR].[COLOR=#0066CC]target[/COLOR], [COLOR=#FF0000]"scaleX"[/COLOR], Elastic.[COLOR=#006600]easeOut[/COLOR], [COLOR=#0066CC]e[/COLOR].[COLOR=#0066CC]target[/COLOR].[COLOR=#006600]scaleX[/COLOR], [COLOR=#CC66CC]1[/COLOR], [COLOR=#CC66CC]1[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#66CC66])[/COLOR];

```

[COLOR=#66CC66]}[/COLOR]

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