Copy link to clipboard
Copied
Slowly learning my way into AS3, here is the original code that i am trying to move into AS3 from AS2. The function is to allow the mouse over state to stay selected until the mouse moves off of the selected area. Here is the AS2 code:
mc.onRollOver = function(){
mc.gotoAndStop(2);
}
mc.onRollOut = function(){
mc.gotoAndStop(1);
}
How i have changed it: This is where i need help
mc.addEventListener(MouseEvent.ROLL_OVER)=function(){
mc.gotoAndStop(2); }
mc.addEventListener(MouseEvent.ROLL_OVER)=function(){
mc.gotoAndStop(1); }
What am i missing with the code?
1 Correct answer
I tried this code, and got a duplicate error:
mc.addEventListener(MouseEvent.ROLL_OUT, overHandler);
function overHandler(evt:MouseEvent):void {
mc.gotoAndStop(2);
}
DId you define the overHandler function twice? That's about the only way you could get a duplicate error... I think you want:
mc.addEventListener(MouseEvent.ROLL_OUT, outHandler);
function outHandler(evt:MouseEvent):void {
mc.gotoAndStop(1);
}
Copy link to clipboard
Copied
In AS3 there are event listeners and event handlers... you are trying to combine the two into one, which some people seem to get away with sometimes. But you should keep them separate, especially if you're in a learning phase...
mc.addEventListener(MouseEvent.ROLL_OVER, overHandler);
function overHandler(evt:MouseEvent):void {
mc.gotoAndStop(2);
}
Copy link to clipboard
Copied
Do i need a second part to the code for when the mouse leaves the hovered area? Right now i mouse over the area and it stays even though i move my mouse off.
I tried to add another instance of the code with a '1' instead of a '2' and got a duplicate instance error.
Copy link to clipboard
Copied
I tried this code, and got a duplicate error:
mc.addEventListener(MouseEvent.ROLL_OUT, overHandler);
function overHandler(evt:MouseEvent):void {
mc.gotoAndStop(2);
}

Copy link to clipboard
Copied
I tried this code, and got a duplicate error:
mc.addEventListener(MouseEvent.ROLL_OUT, overHandler);
function overHandler(evt:MouseEvent):void {
mc.gotoAndStop(2);
}
DId you define the overHandler function twice? That's about the only way you could get a duplicate error... I think you want:
mc.addEventListener(MouseEvent.ROLL_OUT, outHandler);
function outHandler(evt:MouseEvent):void {
mc.gotoAndStop(1);
}
Copy link to clipboard
Copied
thanks! i knew i was missing something small like that!
Copy link to clipboard
Copied
.

