need help with dynamic navigation

By AndrewPSW | Jun 29, 2009

actionscript3

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[i];

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));

}

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0