# Need help with dynamic navigation

**URL:** <https://forum.kirupa.com/t/need-help-with-dynamic-navigation/291384>\
**Category:** Uncategorized\
**Created:** [June 29, 2009, 12:45am UTC](https://forum.kirupa.com/t/need-help-with-dynamic-navigation/291384 "2009-06-29T00:45:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewPSW](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@andrewPSW](https://forum.kirupa.com/u/andrewPSW)\
**Post date:** [June 29, 2009, 12:45am UTC](https://forum.kirupa.com/t/need-help-with-dynamic-navigation/291384/1 "2009-06-29T00:45:24Z")

</div>

Hello everyone,

The Action script code below takes the strings in the array (pgtit) and creates a dynamic navigation bar I am trying to trace the index number of the array being click I just seem to get -1. Thanks for any help on this.

var pgtit:Array=[“link1”,“link2”,“link3”,“link4”];  
var xPos = 0;

var menuHolder:MovieClip = new MovieClip;  
addChild(menuHolder);

for(var i:uint = 0; i \< pgtit.length; i++){

```
var btn:MovieClip = new MovieClip();
btn.buttonMode = true;
btn.mouseChildren = false;

var titles:TextField = new TextField();
titles.autoSize = TextFieldAutoSize.LEFT;
titles.selectable = false;
titles.text = pgtit*;

menuHolder.addChild(btn);
menuHolder.y = 100;
btn.addChild(titles);	
titles.x = (btn.width/2) - (titles.width/2);
titles.y = (btn.height/2) - (titles.height/2);

btn.width = 100;
btn.x = xPos;
xPos += btn.width+2;

btn.addEventListener(MouseEvent.CLICK, arraynum);

```

}

function arraynum(event:MouseEvent):void{  
trace(pgtit.indexOf(event.target.name));

```
}
```
