Create a simple sliding menu - part 3
ericlin@ms1.hinet.net


If you are not very familiar with action script and functions, it is better to create your menu by drag instance from library and create new symbol and codes each movieClip instance separatively.

If we want dynamically create these menu, there are several "advanced" technique we should know. I strongly advise you to learn these "advanced" script, because this technique is very useful.

1.

When we have a button and a textbox in a movieClip symbol, how do we make different instance of this symbol behave differently ? For example, we have two instance of submenu symbol. Instance one should have a text showing "submenu 1" and the button click should getURL("page1"); While the second instance should have a text showing "submenu 2" and the button click should getURL("page2") ?

We know that, edit the symbol will affect all instances. There are two ways. 

One is using variable. For example, set instance1.text="submenu 1" will make it show "submenu 1"; For the button, If we say: on(release){getURL(page);} Then we can set instance1.page="page 1" to make it onRelease -> getURL("page 1");

The other way:pass the parameter to a central governer for handle. For example: on(release){_root.buttonsClick(this);}

Now at _root we script a function:

function buttonsClick(clip){
    if(clip==_root.instance1){
        //do something
    }else if(clip==_root.instance2){
        //do another thing
    }
}

 That technique is essential to enable out submenu buttons to do our job.

Those are for Flash 5. In Flash MX, we can directly assign onRelease codes to a button dynamically.


The next job is: How to make onClipEvent(enterFrame) to a symbol ?

In Flash MX, it is simply a script in Frame 1 of the symbol : onEnterFrame=function(){}

In Flash 5, I add an empty movieClip to convey my onClipEvent(enterFrame) block.


Here I would like to mention about the script of align controller.

For simplicity, in the previous session, I script alignment by "menu3._y=menu2._y+menu2._height;"

Since we dont know how many menu we are going to deal with, so we write an align codes:

arrange = function () {
    sumY = 0;
    for (var k = 0; k<menuArray.length; k++) {
        myMenu["holder"+k]._y = sumY;
        sumY += myMenu["holder"+k]._height;
    }
};

OK. Create a sliding menu might need 1 hour. To write this tutor, I took 6 hours. Forgive my English.

¡@