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

How to put my character walking with keyboard keys in another frame?

New Here ,
Apr 13, 2015 Apr 13, 2015

Hello,

I'm studying multimedia and I need to do a simple game using Flash. I've seen a few tutorials about how to put a character walking and I was able to do it, but once I put the char in (for example) the third frame it doesnt walk. I have a main menu with a play button, when i click it, it goes to the third frame (where the character and the level is. I want the game to stop at that frame but at the same time be able to make the character walk using keyboard keys.

Can anybody help me? Am I doing anything wrong?

Thank you.

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

LEGEND , Apr 14, 2015 Apr 14, 2015

I updated my file to have the button - use the same link to get the updated version.  It still works properly.

Translate
LEGEND ,
Apr 13, 2015 Apr 13, 2015

Which frame is the code in for the walker?  Do you get any errors?

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 ,
Apr 13, 2015 Apr 13, 2015

I put my character and the respectives codes to walk all in the frame 3. If I put stop() in the frame it stays at the frame but i can't move the character, when I remove the stop() it plays the frame and comes back to the beggining (i don't have forth/fifth/sixth frame so it passes the frame without stopping it)

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 ,
Apr 13, 2015 Apr 13, 2015

How is the animation done?  Is it a movieclip that contains the animation or is it along the timeline where the code is?

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 ,
Apr 13, 2015 Apr 13, 2015

It's a movieclip with animation on it (kind of a sprite that i made) and in a different layer (same frame) it has the actions because it's as3

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 ,
Apr 13, 2015 Apr 13, 2015

You mention Sprite... Sprites do not have a timeline so that might be part of the problem.  Convert it to a Movieclip object if you did set it up as a Sprite

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 ,
Apr 14, 2015 Apr 14, 2015

I'm not sure if it is a sprite, the character is a movieclip with two frames inside of it. If i replay over and over it looks like the character is moving (in the same spot of course)

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
Contributor ,
Apr 14, 2015 Apr 14, 2015

I remember something similar happened to me but couldnt reproduce it now. Maybe you can paste your code here?

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 ,
Apr 14, 2015 Apr 14, 2015

I'm still initiating on Flash so I used the Code Snippets given there. This is the code to make my character (instance name: char) walk. I know I need to put gravity but I haven't done that yet.

var upPressed:Boolean = false;

var downPressed:Boolean = false;

var leftPressed:Boolean = false;

var rightPressed:Boolean = false;

char.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey_5);

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed_5);

stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed_5);

function fl_MoveInDirectionOfKey_5(event:Event)

{

  if (upPressed)

  {

  char.y -= 5;

  }

  if (downPressed)

  {

  char.y += 5;

  }

  if (leftPressed)

  {

  char.x -= 5;

  }

  if (rightPressed)

  {

  char.x += 5;

  }

}

function fl_SetKeyPressed_5(event:KeyboardEvent):void

{

  switch (event.keyCode)

  {

  case Keyboard.UP:

  {

  upPressed = true;

  break;

  }

  case Keyboard.DOWN:

  {

  downPressed = true;

  break;

  }

  case Keyboard.LEFT:

  {

  leftPressed = true;

  break;

  }

  case Keyboard.RIGHT:

  {

  rightPressed = true;

  break;

  }

  }

}

function fl_UnsetKeyPressed_5(event:KeyboardEvent):void

{

  switch (event.keyCode)

  {

  case Keyboard.UP:

  {

  upPressed = false;

  break;

  }

  case Keyboard.DOWN:

  {

  downPressed = false;

  break;

  }

  case Keyboard.LEFT:

  {

  leftPressed = false;

  break;

  }

  case Keyboard.RIGHT:

  {

  rightPressed = false;

  break;

  }

  }

}

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
Contributor ,
Apr 14, 2015 Apr 14, 2015

thats your code at frame 3? where is the stop();? is there other code on other frames and inside the "char"? And did you create an Action layer?

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 ,
Apr 14, 2015 Apr 14, 2015

If I put stop(); the character won't move, if I take the stop(); it goes the the next frame (this case is the beggining). Yes, the actions are in a separated layer from the character.

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 ,
Apr 14, 2015 Apr 14, 2015

Where are you placing that stop()... which timeline?

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 ,
Apr 14, 2015 Apr 14, 2015

After that code (the one I put above), I clicked twice the Enter and then wrote stop(); when I tested it, it went to the frame and stopped there, the character didnt move.

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 ,
Apr 14, 2015 Apr 14, 2015

I have recreated what you describe doing and I do not see any problem with it.  You can download the file I created and compare it to your own.  If you see the same problem then explain what that is.  Maybe some difference between the two will spark something you have not mentioned that might be the problem... or, maybe your file is corrupt and you should start a new one.

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

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 ,
Apr 14, 2015 Apr 14, 2015

I downloaded yours and it did go well, it moved but once I put the a button in the first frame saying to go to the thirf frame it stopped moving. Maybe the problem is the button. I put gotoAndStop(3) and I put gotoAndPlay(3) and none of them puts the character moving... Any idea how to put it working?

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
Contributor ,
Apr 14, 2015 Apr 14, 2015

"didnt" move means the two-frame-animation inside the movieclip is not playing or the arrowkeyactions dont work? or both?

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 ,
Apr 14, 2015 Apr 14, 2015

I clicked the button, it went to the third frame, stopped there. The movieclip played the two frames inside of it (repeatedly) but when i used the keyboard arrows the character didn't move.

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 ,
Apr 14, 2015 Apr 14, 2015

I updated my file to have the button - use the same link to get the updated version.  It still works properly.

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 ,
Apr 14, 2015 Apr 14, 2015

It worked perfectly, thank you so, so much. I know what happened now, when I converted to symbol my Play Button I used Button while you used MovieClip. I changed mine to MovieClip and now it works flawlessly. I click play it goes to frame number 3, the two-frame-animation of the character works and I can move it with the keyboard arrows the way I want . Thanks again, very much appreciated

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 ,
Apr 14, 2015 Apr 14, 2015
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