Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Dynamic Functions for a menu in Flash

Hi all...

I have a Flash movie that reads in a varying number of items from an array.  I want it to dynamically create the onRelease functions for the item.

For Example:

Menu 1 has 3 items, so Flash creates MENU 1, with 1 2 3 underneath.  when you click on 1, you bring up item1, click on 2, bring up item2, etc.
Menu 2 has 5 items, flash does as above, but with 5 clickable links going to item1-5

Now, i have it hardcoded as "btn1.onRelease = function() { blah }" "btn2.onRelease..." etc. but i wanted to know if there's a dynamic way to do it.

Any help will be appreciated. An answer to the above or a better way to do it will be accepted. Thanks!
  • 2
1 Solution
The following code i took from an XML menu I created (did it based on an XML-menu tutorial):

        subs = menu.firstChild.childNodes.childNodes;
        amount = subs.length;
        for (b=0; b<=amount; b++) {
            _root.attachMovie("submenuItem", "subitem"+b, b+20);
            _root["subitem"+b].nametxt = subs[b].attributes.id;
            _root["subitem"+b].itemUrl = subs[b].attributes.theURL;
            _root["subitem"+b].itemTarget = subs[b].attributes.Target;

            // put them in the right possition
            _root["subitem"+b]._y = topypos+(_root["subitem"+b]._height*b)+(_root["item"+nummer]._height);
            _root["subitem"+b]._x = startxpos;

In the above there is a button-movie ready for duplication. So the button holds the "onClick" action allready.

In your situation it would be something like this:
for (b=0; b<subbuttonamount; b++) {
             this["btn" + b].onRelease = function() { getURL("abc.htm") };

Hope the examples get you further!?
recommend points for dutchfoxer  :)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now