Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Noob transition to AS3 question

Community Beginner ,
Jul 08, 2009 Jul 08, 2009

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?

TOPICS
ActionScript
956
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jul 09, 2009 Jul 09, 2009

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);

}

Translate
LEGEND ,
Jul 08, 2009 Jul 08, 2009

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2009 Jul 08, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2009 Jul 08, 2009

I tried this code, and got a duplicate error:

mc.addEventListener(MouseEvent.ROLL_OUT, overHandler);

function overHandler(evt:MouseEvent):void {

     mc.gotoAndStop(2);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 09, 2009 Jul 09, 2009

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2009 Jul 09, 2009
LATEST

thanks! i knew i was missing something small like that!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 09, 2009 Jul 09, 2009

.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines