So what i want is:
i have a charicter, and when the left key is pressed the charicter moves left while playing a Movie clip of the charicter walking stored in the library. once that is done the charicter stays pointed in that direction unil it is pointed right by the right key. going up of down does not need any special animations and i can already keep the charicter on the screen
here is a sample of the code for moving left
if (Key.getCode() == Key.LEFT) {
//plays mcwalkL
gotoAndPlay(_root.mcwalkL);
//Stops player from exiting the screen
if (this._x > MIN_X){
this._x = this._x - 15;
//facing sets the charicter in same direction they walked
facing = 2;
}
} if (facing = 2){
gotoAndPlay(_root.mcstandL);
MIN_X is the edge of the sceen
mcstand - is the object with the coding every clip of mc (main charicter) is either pointed right. facing=1, or left, facing = 2 containing a L after it
the coding for right movment if staments is identical only without the L
when playing this. i can move the charicter around the screen keeping them in the area i need it. But the animation does not play so i have a standing guy floating around
Ok, I believe you have to add a listener to find out what key was pressed.
I am not sure if this works in Flash 5 since I don’t use it, but you can try this…
//define listener object
keyListener = new Object();
//create function for when a key is pressed
keyListener.onKeyDown = function() {
keypressed = Key.getCode();
//if Key.getCode == Key.LEFT
if (keypressed == Key.LEFT) {
//plays mcwalkL
gotoAndPlay(_root.mcwalkL);
//Stops player from exiting the screen
if (this._x>MIN_X) {
this._x = this._x-15;
//facing sets the charicter in same direction they walked
facing = 2;
}
}
if (facing == 2) {
gotoAndPlay(_root.mcstandL);
}
};
//adds listener to see if key was pressed
Key.addListener(keyListener);
im more concerned about the gotoAndPlay because it is in all the instances when the charicter moves. and it does not work.
The item is stored in a library and if there is another function that would work for that it would be helpful
Right now im guessing I used the gotoAndPlay function wrongly
thank you lostinbeta ,but that does not seem to work in flash 5 i plugged that in for walking left and i couldnt make the charicter walk that way. What does a listener do? i am able to have the charicter move but not play the animation
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
//plays mcwalkL
gotoAndPlay(_root.mcwalkL);
//Stops player from exiting the screen
if (this._x>MIN_X) {
this._x -= 15;
//facing sets the charicter in same direction they walked
facing = 2;
}
}
if (facing == 2) {
gotoAndPlay(_root.mcstandL);
}
}
I also changed this._x = this._x-15; to this._x -= 15; it does the same thing, but is much easier
Im sorry i did not change the code for right in the keydown += does work but the problem is it is not in a frame it is saved as a movie clip in my library so
_root.mcwalkL.gotoAndPlay(frame#)
would not work is there another fuction that would work with stored movie clips
the gotoAndPlay operation is not what i needed in this code so i went for the attachMovie operation; however only the mcwalk2 animaiton plays and the charicter cannot move here is what i got so far
if (Key.isDown(Key.LEFT)) {
// clears the previous animation
// plays the correct animation
attachMovie("mcwalk2", "mc", 1);
// facing keeps charicter in right direction when no buttons are pressed
// clears the previous animation
removeMovieClip ("mc");
facing = 2;
if (mc._x>MIN_X) {
mc._x -= 15;
}
if (facing == 1) {
attachMovie("mcstand1", "mc", 1);
i typed this into a layer that spans the whole movie and i can keep the background the same.
also when is it better to use duplicateMovie operation?
Well, I am not 100% on this, but I believe for what you are trying to do, it would only work if your if actions are on your movie clip in an onClipEvent (enterFrame) handler.
When is it better to use duplicateMovieClip for what or instead of what?
::this would be a lot easier to solve if I had flash 5 :-\ :(::
Anyone else reading this have Flash 5 that can help?