Dynamic Buttons

I need help in creating a dynamic button. Basically I want to have a movieclip in the library with a button and dynamic text box in it.
Therefore, I will call the attached movieClip and populate the buttons based on the values of my array. I believe I need to have a onmouse event for each movieclip/button right? How do I do this?

TabArray = [“menu1”, “menu2”, “menu3”];

_root .onLoad = function ()
{

    var  iMenuLength = TabArray.length; 

    for (j=0; j < iMenuLength; j++) 
     {

       MenuName=TabArray[j];
       attachMovie("Tab_Mc", myName , (j*10));
       this[MenuName]._x = j * this[MenuName]._width;
       this[MenuName]._y = 150;
       this[MenuName]._alpha = 75;
     }

};

Hi,
I’m not sure about your code there, but the attached might be of use. The code for duplicating the button is on fr1 inside the button, to add to the number of buttons, just add another word in the array(), and remove words to reduce the number. The code for the button is mc.RmenuItem and is self explanatory.

Hope its what you need

Cheers

SteveD

Good example, it does what I want, almost. Question, what if I want to add a hyperlink for each dynamic button. How would you incorporate that logic? Examples would be great.

Hi,
Well…unless your array was populated with the url addresses you would need to write if else arguments :

onRelease = function(){
if (label==labelName){
getURL(whatever);
} else if( llabel==somethingelse){
getURL (something else);
etc etc…
}
}

However, you could make your array the url addresses, but that might look a bit messy, though it would be possible to drop a mask in the button and block most of it out so that all that appeared was a name - example (“http://www.somesite.com”,1)
could appear as somesite, then I am not sure about the code, you would need to play around with it a bit, but, you would only need one line as in :
getURL(label) or something like that, you would need to test a couple of variations and that does not look like it would work to me. If you work it out let me know, I’ll have a play around myself in the meantime

Anyway hope that helps

Cheers

SteveD

Thanks Steve. I got it, you gave me all the information I need to
get started. Many thanks again.

One more minor thing Steve. Can you please show me the same exact code example, but instead of using the duplicateMovieClip function use the AttachMovie function?

I’m very interested in using the AttachMovie function.

Here is a type of thing I did with this a while ago if you want to look at it. It isn’t exactly super duper, but its something.
(check attachment)

In the main script you see a line that says

menuObj.button.loc = "You Clicked "+labels*;

That was my test area, where I had a variable called “loc” in the movie clip I was attaching, and in that movie clip I had a button when on(release) it traced the variable “loc”

If you look in the Library “Button” is the main button to which you do the editing. If you open that up you will see two layers, 1 with a textbox that lists the label, and another with a button (which is Button2 in the library). There is an action on the button layer that says

loc = null

This sets our variable, then the actions on the button say

on (release) {
trace(loc);
}

You can easily change that to getURL(loc, “_blank”) or whatever, but this brings us back to the line that says menuObj.button.loc = "You Clicked "+labels*;, but pulls the loc from the labels array.

Yeah… this isn’t good, so what we need to do here is create ANOTHER array that holds the URLs. I guess we could call it “urls”.

So the code will now be…

menuObj.button.loc = "You Clicked "+urls*;

I am really bad at explaining things sometimes, so if I made no sense, let me know what your confused on.

Oh yeah, and to get attachMovie() to work you must right click on the object you are attaching in the library and choose “Linkage”, then check the “Export for Actionscript” checkbox, and give it a name, and that name is used in your attachMovie() function.

Thanks…It’s a perfect example. I’m trying to do something very simular.
I couldn’t figure out how to track which button the user selected.
It never occurred to me to add a variable in the attached button. Hotdog…hee hee…hee.

menuObj.button.loc = "You Clicked "+labels*;

As far as getting the urls…your right just add an extra
array, no problem at all.

Thanks a million.

No problem :slight_smile:

I did that a long time ago… wasn’t even supposed to be a dynamic menu, but instead ended up turning into one… Ironic eh?

Hi,
7of9 glad you got that sorted then, glad to have helped.

lostinbeta - nice code, and easy to follow logic

Cheers

SteveD

SteveD: Your code was nice too, I don’t think I could have come up with something like that on my own. Good Job.