hey guys,
I have made a site in AS3.0 code and it’s working fairly well but theres alot of things i’m trying to update to make the code a little more reusable. For starters
I have a function that creates a little pop-up text when I roll over a button. The text is a class that I created in the Flash IDE instead of dynamically drawing it with actionscript.
Here is the code for the pop up text instance called “enter_text” as it rolls over the movie clip “preloader_mc”
//add listeners to the preloader_mc movie clip on stage
preloader_mc.buttonMode=true;
preloader_mc.addEventListener(MouseEvent.ROLL_OVER, pop_up, false, 0, true);
preloader_mc.addEventListener(MouseEvent.ROLL_OUT, pop_out, false, 0, true);
// variables for the pop-up function
var pop_up_text:MovieClip = new enter_text();
var timer:Timer = new Timer(300, 1);
var isOn:Boolean = false;
function pop_up(e:MouseEvent):void {
preloader_mc.gotoAndStop("over")
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
function onTimer(e:Event):void {
addChild(pop_up_text);
pop_up_text.x = mouseX+35;
pop_up_text.y = mouseY+15;
isOn=true;
stage.addEventListener(MouseEvent.MOUSE_MOVE, follow_cursor, false, 0, true);
function follow_cursor(event:MouseEvent):void {
pop_up_text.x = mouseX+35;
pop_up_text.y = mouseY+15;
}
}
}
function pop_out(e:MouseEvent):void {
preloader_mc.gotoAndPlay("out")
if (isOn) {
removeChild(pop_up_text);
isOn=false;
} else {
timer.stop();
}
}
the code in action can be seen at “www.brandonserbecdesign.ca” the pop-up function is when u roll over the “bs” right after the preloader, and it says “enter”. My problem is i also reuse this function when you enter the site and roll over the draggable menu. Ofcourse I have to recode everything using different names for the functions and variables when I use the function on a different object as the target. How can I make this more reusable by passing in parameters for the class that is to pop up when I roll over a different object?
THanks so much whoever responds!