AS3 Button Walkthrough - Help Please
Could someone help me out some if you have time. I wanted to get a little walkthrough on setting up my buttons on my navigation bar, but done correctly, meaning I would like all my as on one layer in the timeline. I have seen tutorials all over the web but none of them are really working for the as3 that I have done up to use. Im not planning on using any kind of button base, just the word itself.
Below is what I have for my code. Now I would just like to set the button up properly to function with this.
var btnLabels:Array =
for (var i:Number = 0; i < btnGroup.numChildren; i++)
var btn:MovieClip = MovieClip(btnGroup.getChildAt(i));
btn.id = i;
btn.buttonMode = true;
btn.mouseChildren = false;
btn.btnLabel.text = String(btnLabels[i]);
btn.addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
frameNum = e.target.id + 1;
i came back to this post several times wanting to help, and each time became frustrated by the way it was presented, lacking some important information, so i gave up each time. please try to be as informative, yet succint, in your descriptions and requests as possible- otherwise it becomes real hard to figure out what someone is asking or wants to do.
there are 3 lines of code, which, unless you have left out some crucial information, tell me that your code will not work.
what is btnGroup.numChildren ? is there a btnGroup movieclip on the stage WITH children already? if so, then why have
what are you trying to accomplish there?
and of course, if the btnGroup movieclip is already populated with 5 children, then how are they being labeled with text with this line
unless i am missing the boat, i deduce that you have a movieclip called btnGroup which will act as the 'button navigation bar'. then, you have or need 5 buttons which will be labeled "HOME", "ABOUT" etc, which when clicked, will navigate to frames 1-5.
those 5 buttons all need a dynamic text field, right? IF those buttons(movieclips) are already on the stage with dynamic text fields inside of them, how are the text fields named? all as btnLabel ? those text fields would have to have been given unique instance names, and then accounted for, probably in a separate array.
if those 5 button/movieclips are NOT already in the btnGroup movieclip, then they need to be added as children to that movieclip.
do you see these issues?
i would suggest that you have your btnGroup movieclip symbol on the stage, and that in your library you have a movieclip symbol with the linkage name btn1 . this btn1 symbol will have a dynamic text field inside of it with the instance name "btnLabeText"
your btnLabelsArray were already in String form, so btn.btnLabel.text = String(btnLabels[i]); made no sense. also of course btn.btnLabel.text = String(btnLabels[i]); didn't make sense either.
this redone code should do what i believe you want, as long as your file is set up correctly to. i don't encourage frame based navigation, but if that is the stage you are at, then at least understand it. make sure that the code is on the first fame, and the btnGroup symbol carries over the five frames as in the attached screenshot
so now the for loop is truly relating to the btnLabels array, and will add a child to the
everthing else should make sense.
i hope i understood your needs correctly, and if so, that this helps.