• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Switch case trouble... it looks fine but output says otherwise

Explorer ,
Jun 19, 2009 Jun 19, 2009

Copy link to clipboard

Copied

Hi;

I'm hoping someone can be kind enough to help me with my annoying switch case problem that I've been staring at for hours with very little succsess.

function cool(event:KeyboardEvent):void

{
switch(event.keyCode)
{
case  Keyboard.LEFT : shoot_mc.x -= 5
break;
case  Keyboard.RIGHT : shoot_mc.x += 5
break;
case Keyboard.UP : shoot_mc.y += 5
break;
case Keyboard.DOWN : shoot_mc.y -= 5
break;
}
}
TOPICS
ActionScript

Views

1.6K

Translate

Translate

Report

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

LEGEND , Jun 25, 2009 Jun 25, 2009

The problem may not have to do with the switching and keyboard stuff, but just in case, here's a sample file with the keyboard controlling the position of a shoot_mc:

http://www.nedwebs.com/Flash/AS3_Key_Switch.fla

Votes

Translate

Translate
LEGEND ,
Jun 19, 2009 Jun 19, 2009

Copy link to clipboard

Copied

It plays fine too (with a listener in the loop).  What is the output saying?

Update: I should add that y increases as you move down the stage, so you probably want to switch +=/-= between the UP and DOWN keys

Votes

Translate

Translate

Report

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
Explorer ,
Jun 19, 2009 Jun 19, 2009

Copy link to clipboard

Copied

these are the errors I recieve... except I get 8 of them one for each command. I do have a stage event listener in place.

1119: Access of possibly undefined property x through a reference with static type Class.

1119: Access of possibly undefined property y through a reference with static type Class.

UPDATE: I made a newbie error and after a break from the computer I noticed it but I still got an error. I forgot to put the words event: in the listener. Here is my listener and the error that I get a lot.

stage.addEventListener(event:KeyboardEvent.KEY_DOWN, cool);

1084: Syntax error: expecting rightparen before colon.

Votes

Translate

Translate

Report

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 ,
Jun 20, 2009 Jun 20, 2009

Copy link to clipboard

Copied

For the event listener, the following is correct:

stage.addEventListener(KeyboardEvent.KEY_DOWN, cool);

For the other 8 errors, what is the shoot_mc?  How is it created/added to the stage?  You appear to have used "Class" to define its class.

Votes

Translate

Translate

Report

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
Explorer ,
Jun 20, 2009 Jun 20, 2009

Copy link to clipboard

Copied

Shoot_mc is a movie clip thats pulled from my library used as a cursor.

Votes

Translate

Translate

Report

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
Explorer ,
Jun 24, 2009 Jun 24, 2009

Copy link to clipboard

Copied

I posted this a couple post up in a edit but I think no one saw it. I'm no longer recieving the shoot_mc errors I forgot to put the words event: in the listener. Here is my listener and the error that I get a lot.

1084: Syntax error: expecting rightparen before colon.

Votes

Translate

Translate

Report

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
Jun 25, 2009 Jun 25, 2009

Copy link to clipboard

Copied

Change

stage.addEventListener(event:KeyboardEvent.KEY_DOWN, cool);

to

stage.addEventListener(KeyboardEvent.KEY_DOWN, cool);

Votes

Translate

Translate

Report

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
Explorer ,
Jun 25, 2009 Jun 25, 2009

Copy link to clipboard

Copied

I did that and got another error. I decided to post the entire switch function and listener since that might help.

stage.addEventListener(KeyboardEvent.KEY_DOWN, cool);
function cool(event:KeyboardEvent.KEY_DOWN):void
{
switch(event.keyCode)
{
case  Keyboard.LEFT : shoot_mc.x -= 5
break;
case  Keyboard.RIGHT : shoot_mc.x += 5
break;
case Keyboard.UP : shoot_mc.y += 5
break;
case Keyboard.DOWN : shoot_mc.y -= 5
break;
}
}

Votes

Translate

Translate

Report

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
Jun 25, 2009 Jun 25, 2009

Copy link to clipboard

Copied

Change

function cool(event:KeyboardEvent.KEY_DOWN):void

to

function cool(event:KeyboardEvent):void

Votes

Translate

Translate

Report

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
Explorer ,
Jun 25, 2009 Jun 25, 2009

Copy link to clipboard

Copied

Thanks raymond for the help. I'm not sure why but I get the same errors that

I posted after doing what you said.

Votes

Translate

Translate

Report

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 ,
Jun 25, 2009 Jun 25, 2009

Copy link to clipboard

Copied

The problem may not have to do with the switching and keyboard stuff, but just in case, here's a sample file with the keyboard controlling the position of a shoot_mc:

http://www.nedwebs.com/Flash/AS3_Key_Switch.fla

Votes

Translate

Translate

Report

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
Explorer ,
Jun 25, 2009 Jun 25, 2009

Copy link to clipboard

Copied

thank you soo much Ned! I looked at your code and it was identical to mine,

so i looked at your library and my library and noticed a difference. You

exported as symbol1 when I exported as shoot_mc. The export was creating a

conflict. Thank you for your help!! Now a lot of my projects will work

thanks to this discovery.

Votes

Translate

Translate

Report

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 ,
Jun 25, 2009 Jun 25, 2009

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

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