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

Rotate and stop rotating an object

New Here ,
Oct 04, 2010 Oct 04, 2010

Hi

I want to rotate an object using the arrows on the keyboard when the mouse is over the object and it should not be possible to rotate the object when the mouse is not on the object.

I know how to rotate the object, when the mouse is over the object, but when I put the mouse outside the object I can still rotate the object. How do I make the rotation stop?

square1.addEventListener(MouseEvent.MOUSE_OVER, around);

square1.addEventListener(MouseEvent.MOUSE_OUT, normal);

function around(e:MouseEvent):void {

stage.addEventListener(KeyboardEvent.KEY_DOWN, rotate);

}

function rotate(event:KeyboardEvent):void {

switch (event.keyCode)

{

case Keyboard.RIGHT:

{

square1.rotation += 90;

break;

}

case Keyboard.LEFT:

{

square1.rotation -=90;

break;

}

}

}

function normal(e:MouseEvent):void {

     trace("The object should not be rotating");

}

Thanks

TOPICS
ActionScript
1.2K
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

Community Expert , Oct 04, 2010 Oct 04, 2010

use:


square1.addEventListener(MouseEvent.MOUSE_OVER, around);

square1.addEventListener(MouseEvent.MOUSE_OUT, normal);

function around(e:MouseEvent):void {

stage.addEventListener(KeyboardEvent.KEY_DOWN, rotate);

}

function rotate(event:KeyboardEvent):void {

switch (event.keyCode)

{

case Keyboard.RIGHT:

{

square1.rotation += 90;

break;

}

case Keyboard.LEFT:

{

square1.rotation -=90;

break;

}

}

}

function normal(e:MouseEvent):void {

stage.removeEventListener(KeyboardEvent.KEY_DOWN, rotate);

}

Translate
Community Expert ,
Oct 04, 2010 Oct 04, 2010

use:


square1.addEventListener(MouseEvent.MOUSE_OVER, around);

square1.addEventListener(MouseEvent.MOUSE_OUT, normal);

function around(e:MouseEvent):void {

stage.addEventListener(KeyboardEvent.KEY_DOWN, rotate);

}

function rotate(event:KeyboardEvent):void {

switch (event.keyCode)

{

case Keyboard.RIGHT:

{

square1.rotation += 90;

break;

}

case Keyboard.LEFT:

{

square1.rotation -=90;

break;

}

}

}

function normal(e:MouseEvent):void {

stage.removeEventListener(KeyboardEvent.KEY_DOWN, rotate);

}

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
New Here ,
Oct 04, 2010 Oct 04, 2010

It worked!!

Thank you very much

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 Expert ,
Oct 04, 2010 Oct 04, 2010
LATEST

you're welcome.

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
LEGEND ,
Oct 04, 2010 Oct 04, 2010

You need to remove keyboard event listener from stage in normal function.

Also, case in switch doesn't need curly brackets.

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