Hi Guys!
It’s been a while since I posted here but here I am again with a basic question.
I just recently caved in and promised myself never to use AS 2.0 again and force my brain to get in line with the new AS 3.0.
However, as expected, I’m having some transitional issues which I’m sure you can help me with. Here is the problem:
Coming from a Design background I usually like to code in a simple way. My usual method of doing basic stuff is to just make a function that takes care of all the situations where that code is constantly reused, for instance, when using Rollover actions I’m used to making a single function which takes care of most Rollover effects in my projects, this is an example:
stop();
test_btn._alpha = 60;
function rollOverEffect(targetMC:String) {
this[targetMC]._alpha = 100;
trace("Rollover Called");
}
function rollOutEffect(targetMC:String) {
this[targetMC]._alpha = 60;
trace("Rollout Called");
}
test_btn.onRollOver = function() {
rollOverEffect("test_btn");
};
test_btn.onRollOut = function() {
rollOutEffect("test_btn");
};
Ok, this works perfectly! The button passes a String with the target on which the function is going to perform those actions and I can use it whenever I want with any button as long as I pass the correct argument.
In AS3 this poses a problem…
If I try to follow the same train of though in AS3 it leaves me with something like this:
stop();
import flash.display.MovieClip;
import flash.events.MouseEvent;
teste_btn.addEventListener(MouseEvent.MOUSE_OVER,rollOverEffect);
teste_btn.addEventListener(MouseEvent.MOUSE_OUT,rollOutEffect);
function rollOverEffect(e:MouseEvent){
teste_btn.gotoAndPlay("over");
}
function rollOutEffect(e:MouseEvent):void {
teste_btn.gotoAndPlay("out");
}
My question is, can you guys give me a solution on how to pass an argument from a addEventListener to a function? Or an alternative way to get the same results? This has been holding up all my AS3 projects :tired:
Thanks in advance!