Copy link to clipboard
Copied
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.
I updated my file to have the button - use the same link to get the updated version. It still works properly.
Copy link to clipboard
Copied
Which frame is the code in for the walker? Do you get any errors?
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
How is the animation done? Is it a movieclip that contains the animation or is it along the timeline where the code is?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
I remember something similar happened to me but couldnt reproduce it now. Maybe you can paste your code here?
Copy link to clipboard
Copied
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;
}
}
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Where are you placing that stop()... which timeline?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
"didnt" move means the two-frame-animation inside the movieclip is not playing or the arrowkeyactions dont work? or both?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I updated my file to have the button - use the same link to get the updated version. It still works properly.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now