# Menu Creation with ActionScript - Need some help with adding actions

**URL:** https://forum.kirupa.com/t/menu-creation-with-actionscript-need-some-help-with-adding-actions/47119
**Category:** flash
**Created:** [March 31, 2004, 7:44am UTC](https://forum.kirupa.com/t/menu-creation-with-actionscript-need-some-help-with-adding-actions/47119 "2004-03-31T07:44:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![therevolutionco](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@therevolutionco](https://forum.kirupa.com/u/therevolutionco)
#### Post date: [March 31, 2004, 7:44am UTC](https://forum.kirupa.com/t/menu-creation-with-actionscript-need-some-help-with-adding-actions/47119/1 "2004-03-31T07:44:40Z")

</div>

I’ve got a sample flash element that loads an xml file in order to build a menu. I would like to add actions to the flash element (i.e. click on a menu item and go to a particular url), and am unable to get this working properly. If anyone can help me, it would be greatly appreciated.

I’ve attached all of the source code in a zip file.

I’ll paste my actionscript below, which is broken across 2 layers. In addition, I have posted my xml input file below.

========layer 1, frame 1========  
menuClass.prototype = new MovieClip();  
function menuClass(){  
this = \_root.attachMovie(“menu”,“menu”,0);  
this.\_visible = false;  
this.\_data = new XML();  
this.\_data.\_parent = this;  
this.\_data.ignoreWhite = true;;  
this.\_data.load(“menu.xml”);  
this.\_data.onLoad = parseMenu;  
this.init();  
}

Object.registerClass(“menu”,menuClass);

parseMenu = function(){  
nbChilds = this.firstChild.childNodes.length;  
//for(var i=0;i\<nbChilds+1;i++){  
for(var i in this.firstChild.childNodes){  
temp = new itemClass();  
temp.init(i);  
itemMc = temp.mc;  
itemMc.\_y = 20_i;  
itemMc.park = 20_i;  
itemMc.label = this.firstChild.childNodes\*.attributes.label;

for(var j=0;j\<this.firstChild.childNodes\*.childNodes.length;j++){  
itemMc.attachMovie(“sub”,“sub”+j,10_j);  
itemMc[“sub”+j].\_y = 20 + 20_j;  
itemMc[“sub”+j].toto = this.firstChild.childNodes\*.childNodes[j].attributes.label;  
}  
itemMc.distance = j_20;  
}  
var temp = new itemClass();  
temp.init(this.firstChild.childNodes.length);  
var itemMc = temp.mc;  
itemMc.\_y = 20_this.firstChild.childNodes.length;  
itemMc.park = 20\*this.firstChild.childNodes.length;

this.\_parent.\_visible = true;  
}

menuClass.prototype.init = function(){  
this.attachMovie(“mask”,“mask”,300);  
with(this.mask){  
\_y = -1  
\_height = \_root.menu.item4.\_y;  
\_width = 101;  
}

this.createEmptyMovieClip(“topEdge”,203);  
with(this.topEdge){  
lineStyle( 0.25, 0x000000, 100 );  
moveTo( 0,0);  
lineTo(100,0);  
}  
this.setMask(this.mask)  
}

menuClass.prototype.onEnterFrame = function(){

this.mask.\_height = this.item4.\_y+2;

this.createEmptyMovieClip(“leftEdge”,200);  
with(this.leftEdge){  
lineStyle( 0.25, 0x000000, 100 );  
moveTo( 0, 0 );  
lineTo( 0,this.item4.\_y );  
}

this.createEmptyMovieClip(“rightEdge”,201);  
with(this.rightEdge){  
lineStyle( 0.25, 0x000000, 100 );  
moveTo( 100, 0 );  
lineTo( 100,this.item4.\_y );  
}

this.createEmptyMovieClip(“bottomEdge”,202);  
with(this.bottomEdge){  
lineStyle( 0.25, 0x000000, 100 );  
moveTo( 0,this.item4.\_y );  
lineTo( 100, this.item4.\_y);  
}  
}

myMenu = new menuClass();

========Layer 2, Frame 1===========  
this.\_lockroot = true;

itemClass.prototype = new MovieClip();  
Object.registerClass(“item”,itemClass);

function itemClass(){  
this.open = false;  
itemOpen = undefined;  
}

itemClass.prototype.init = function(i){  
this.mc = \_root.menu.attachMovie(“item”,“item”+i,10\*i);  
}

itemClass.prototype.onEnterFrame = function(){

if(this.quel() \<= itemToOpen){  
this.seek = this.park;  
}else if(this.quel() \> itemToOpen){  
this.seek = this.park + distance;  
}else{

}  
this.goEase(this.seek,4);  
}

itemClass.prototype.onRollOver = function(){

if(this.open){  
itemToOpen = undefined;  
itemToClose = this.quel();  
}else{  
itemToOpen = this.quel();  
itemToClose = undefined;  
}  
distance = this.distance ;  
}

itemClass.prototype.onRollOut = function(){  
itemToOpen = Infinity;  
}

itemClass.prototype.quel = function(){  
return Number(this.\_name.slice(4));  
}

itemClass.prototype.goEase = function(target,speed){  
this.\_y = this.\_y + (target - this.\_y)/speed;  
if(Math.abs(this.\_y-target) \< 0.8)this.\_y = target;  
}

===========dynamically loaded xml file contents========  
\<menu\>  
\<menuItem label=“Home”\>  
\</menuItem\>  
\<menuItem label=“Message Board”\>  
\</menuItem\>  
\<menuItem label=“Miscellaneous”\>  
\<sub label=“Slide Show” data=""/\>  
\<sub label=“Animated Beta” data=""/\>  
\<sub label=“Local Weather” data=""/\>  
\</menuItem\>  
\<menuItem label=“Reads”\>  
\<sub label=“Articles” data=""/\>  
\<sub label=“Interviews” data="" /\>  
\</menuItem\>  
\</menu\>
