I’m trying to create a dynamic menu where the menu items are coming from an ASP page. I’m passing a string to the flash movie containing the menu headings, the flash script then creates the appropriate number of copies of a menuitem sub movie. This works fine. The problem however, is that I can’t seem to dynamically set the onPress event for each movie.
It does not work. A hand appears on the movie when the mouse pointer hovers over it which leads me to believe the onPress event can be set this way, but nothing happens when I press the mouse button.
I’m not sure this would happen here, but it’s very likely that it will:
Here you getURL(sURL);, but it’s probable that buttons will link to different URLs, so you’ll probably put them in an array and the use getURL(URL_array*); or something like this. The problem with this is that Flash doesn’t evalute i during the loop, but when you press the button. Which will mess up the whole thing. So careful with that…
CyanBlue: Your code does let me set the onPress event dynamically like I asked, but:
ilyaslamasse: You are absolutely right on all accounts. I did plan to use an array to populate the various onPress events, but as you pointed out: the variable is not used before it’s too late!!
My current solution is a rather dirty programmer’s trick . I store the url in an invisible textbox in the menuitem movie clip, and then let the function make a reference to that textbox’s variable instead.
Well, it’s not very elegant but it works. Any better solutions will be gratefully received! For example, can I create a global variable in the menuitem movie clip, without the use of an extra textbox?
Actually, I don’t need to create the onPress function anymore, since it will always look the same (I just hard-coded it into the menuitem sub movie). It is only included here to make the code easier to understand.
thanx both of you, and please feel free to suggest improvements!
A little bit of research shows that the extra text box is not necessary. I experimentally removed the text box, and the links still work.
I guess this line:
set(“MenuItem”+i+".sURL", arURL*);
automatically creates a global variable in the movie if one does not already exist.
Brilliant! This ASP menu keeps getting better!
Except this prototype is so boring now it’s not really distinguishable from a pure HTML menu… Time to learn some of that fancy Flash magic!