Optimizing Flash Buttons (Part 2)

Last week I shared the method I use to optimize (movieclip) buttons within Flash. Now, I’m going to take it one step further, by putting the following on the first frame of the topmost layer:

_global.path = "/index.php";
_global.pg_1 = _global.path + "?id=1";

function eventListener(my_mc, mcInstance){
my_mc.onRollOver = function(){
my_mc.onRollOut = function(){
my_mc.onRelease = function(){

function getPage(mcInstance){
var newPage = _global["pg_" + mcInstance];

Then, on each movieclip I would place:

var instance = 1; // this number is different for every instance
_root.eventListener(this, _parent["_opt0" + instance + "_mc"], instance);

By creating a function and using it instead of having repetetive onRollover, onRollout movieclip method calls we’ve reduced the likelihood of errors from repetition and made future updates quicker and more efficient.