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(){
this.gotoAndPlay("over");
}
my_mc.onRollOut = function(){
this.gotoAndPlay("out");
}
my_mc.onRelease = function(){
getPage(mcInstance);
}
}
function getPage(mcInstance){
var newPage = _global["pg_" + mcInstance];
getURL(newPage);
}
Then, on each movieclip I would place:
onClipEvent(load){
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.
One Response
eingko weblog » Extending the Movieclip Class in Flash (ActionScript 2.0)
24|Jul|2006 1[...] In Optimizing Flash Buttons (Part 1) and (Part 2) I talked about improving the efficiency of creating movieclip buttons; although the methods/approaches discussed therein are valuable (but that’s for you to decide), sometimes a more powerful or abstract solution is required. In the text that follows I’ll dissect a class that I’ve created that takes my previous functions one step further, and eliminates the need for copying and pasting code repeatedly. Now, let’s jump right in… [...]