Skip to main content
Known Participant
November 23, 2011
Answered

Help? Error 1078 - movieclip and keyboard listener

  • November 23, 2011
  • 3 replies
  • 1417 views

I'm having what's probably a very basic problem, but I keep getting this error message: Error 1079: Label must be a simple identifier. I'm trying to have AS navigate through a panorama I made in photoshop and turned into a movieclip (panorama_mc). I want it to move from end to end (registration point is in the center) without going past the end of the photo on either side. I also want to make sure that when you get to the end, you can navigate back in the other direction.

Here is my code:

panorama_mc.x = 0;

//moves panorama back and forth

stage.addEventListener(KeyboardEvent.KEY_DOWN, rightKeyPressed);

function rightKeyPressed(event:KeyboardEvent):void

{if (panorama_mc.x<=4361 && panorama_mc.x>-4361)

           

          {Keyboard.RIGHT:panorama_mc.x -= 20;}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, leftKeyPressed);

function leftKeyPressed(event:KeyboardEvent):void

{

          if (panorama_mc.x<4361 && panorama_mc.x>=-4361)

          {Keyboard.LEFT:panorama_mc.x += 20;

}

}

 

if (panorama_mc.x>0)

{

          panorama_mc.x= -panorama_mc.width/2;

}

else if (panorama_mc.x < stage.stageWidth - panorama_mc.width)

{

   panorama_mc.x= stage.stageWidth - panorama_mc.width/2 ;

}

}}

stop();

Let me know what you think. Thanks in advance.

This topic has been closed for replies.
Correct answer Ned Murphy

Hi Ned,

Thanks for all your help. Sorry to keep pestering you. That makes sense. But now I'm getting 1084 errors about missing an identifier before case (for both cases). After extenesive googling, I still don't fully understand it, let alone how to fix it. This is what I have now:

{

      switch(event.keyCode)

      {case 1:if (panorama_mc.x<=4361)

        {case

                    Keyboard.LEFT :

        panorama_mc.x += 20

        break;}

{if (panorama_mc.x>=-4361)

                     case

                    Keyboard.RIGHT :

        panorama_mc.x -= 20

            break;}

           }

  }

}


The conditionals should be inside the case code, surrounding the lines where you set the panorama_mc.x property...

function rightKeyPressed(event:KeyboardEvent):void

{

   && panorama_mc.x>-4361){

      switch(event.keyCode)

      {

        case  Keyboard.LEFT :

           if (panorama_mc.x<=4361) panorama_mc.x += 20;

           break;

 

        case  Keyboard.RIGHT :

           if (panorama_mc.x>=-4361) panorama_mc.x -= 20;

           break;

     }

}

Since they only process one line of code the conditionals do not need the braces, though they could still be used.

3 replies

Ned Murphy
Legend
November 23, 2011

Actually, change all that code to be the following and work from there (I have no idea what the bottom portion is supposed to be doing but you have an overabundance of curly braces)...

panorama_mc.x = 0;

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);

function rightKeyPressed(event:KeyboardEvent):void

{

  if (panorama_mc.x<=4361 && panorama_mc.x>-4361){

      switch(event.keyCode)

      {

        case  Keyboard.LEFT :

        panorama_mc.x += 20

        break;

 

        case  Keyboard.RIGHT :

        panorama_mc.x -= 20

        break;

     }

  }

}

Known Participant
November 23, 2011

Thanks for sticking with me here. This basically works, but there's one main problem: Whenever I reach either end of the panorama, I am stuck an unable to navigate back with the other key. For example, I'll be at the dead end on the right side, but the left arrow key won't work. I've ran into this problem earlier today, so that's actually why I had split up the "switch" statement into the two different functions. I thought that would help, but I was mistaken. Any ideas on how to fix this last problem?

Ned Murphy
Legend
November 23, 2011

Divide that conditional up into the two sections of the switch statement. Using the left key you only need to worry about one end and using the right key the other end - I'll let you work out which goes with which.

Ned Murphy
Legend
November 23, 2011

My eyes are failing me (actually it the forum font) but if I see what I think I see, your lines with the Keyboard.left: and Keyboard.RIGHT: are likely the source of the problem.  Try getting rid of those in those two lines, as in...

{Keyboard.RIGHT:panorama_mc.x -= 20;}

becomes

{panorama_mc.x -= 20;}

Ned Murphy
Legend
November 23, 2011

If you go into your Flash Publish Settings and select the option to Permit Debugging and then run the file again, that might help by identifying the line line of your code that is causing the problem.  Try that and see if it does.  It'll be easier than scrutinizing each line for a syntax issue or something of that nature.

Known Participant
November 23, 2011

Hi, thanks for the tip. I believe the following two lines are the problematic ones, but I still can't figure out what the problem is:

{Keyboard.LEFT:panorama_mc.x += 20;

{Keyboard.RIGHT:panorama_mc.x += 20;

Known Participant
November 23, 2011

Yes, I took out those things and confirmed that they were giving me the error messages. Any idea how to fix it and get the mc to run on the keyboard arrows?