PDA

View Full Version : flash 5, move character help



thestick
October 27th, 2002, 06:22 AM
i have only just started, could someone give me some code to make one stickman move left and right, i have walking and still animations, just need the code, i've tried to code it myself but it failed my attemp at code was this -
stop();

function initGame() {

// create the stickman
attachMovie( "stickman", "stickmanstill",1) ;
stickman._x = 275;
stickman._y = 300;
}

function moveStickman(){}
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 10;

} else if (Key.isDown(Key.LEFT)) {
dx = -10;

} else {
// no movement
dx = 0;
}

// move the stickman and limit that movement
stickman._x += dx;
if (stickman._x < 30) stickman._x = 30;
if (stickman._x > 520) stickman._x = 520;

// make the stickman run or stand still
if ((dx != 0) and (stickman._currentFrame == 1)) {
stickman.gotoAndPlay("stickman");
} else if ((dx == 0) and (stickman._currentFrame != 1)) {
stickman.gotoAndPlay("stickmanstill");
}

stickman= running
stickmanstill=standing still

thanx

thestick
October 27th, 2002, 05:20 PM
does anyone knoe the code to make it work coz i'm a real newbie with actionscript and i really need to get this dun, otherewise could someone tell me a link to a site which has a tutorial on it for this sort of thing?
:pirate:

pom
October 28th, 2002, 08:03 AM
Well, what is that code doing, Thestick? I mean, what's the problem?

pom :)

pom
October 28th, 2002, 08:07 AM
One thing I noticed: you attached the stickman clip under the name stickmanstill, so that's how you have to call it when you want to move it. Not just stickman.

pom :cowboy:

thestick
October 28th, 2002, 08:19 AM
my problem is that for some reason when i export the movie all i see is my motion stickman walkng while staying still in the very top left corner. n e ideas? just trying it again give me a sec ...

pom
October 28th, 2002, 08:32 AM
Did you try to replace stickman by stickmanstill in your code?

thestick
October 28th, 2002, 08:46 AM
i'm doing that in a while, i'm at work so i can't i'll tell u whether it worked at 8:00 PM

pom
October 28th, 2002, 09:17 AM
Well, it's 10:20 pm here... :P

thestick
October 28th, 2002, 02:46 PM
could u check why this won't work plz i've tried most things i know and i still don't know why it doesn't work
(flash 5)

Scootman
October 28th, 2002, 11:54 PM
i didnt really check the FLA but... on this line...

function moveStickman(){}

the function declaration... arent the curley brackets supposed to be open here and closed after all the code for that function has been written?? so it would be

function moveStickman(){

code

}

cuz it seems like the function wont do anything when called... if there is no code in it... but im not too hot on functions in flash so im probably wrong

pom
October 29th, 2002, 03:31 AM
That was the problem... :P

thestick
October 29th, 2002, 03:53 AM
i just changed that line and now when i export the movie it comes only shows up as a white screen and not anything else

do u have any ideas?

pom
October 29th, 2002, 03:57 AM
You have to put the closing bracket at the end of the block!!!!!!!!
Statement block must be terminated by '}'
function movestickman() {
Looks pretty clear, doesn't it? :-\

thestick
October 29th, 2002, 04:00 AM
sorry about that i accidently posted the undedited version, read my previous reply which i have just updated to get the relevent flash file
sorry
:x

pom
October 29th, 2002, 04:07 AM
Put a } at the end of your function...

pom
October 29th, 2002, 04:09 AM
Something else, you're trying to attach stickman, but there's no clip called like that in the library. Two of them are called stickmanstill.

thestick
October 29th, 2002, 04:19 AM
stop();

function initGame() {

}
// create the stickman
attachMovie( "stickman", "stickmanstill",20) ;
stickman._x = 275;
stickman._y = 300;
}

function movestickman() {

}
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 10;

} else if (Key.isDown(Key.LEFT)) {
dx = -10;

} else {
// no movement
dx = 0;
}

// move the stickman and limit that movement
stickmanstill._x += dx;
if (stickmanstill._x < 30) stickmanstill._x = 30;
if (stickmanstill._x > 520) stickmanstill._x = 520;

// make the stickman run or stand still
if ((dx != 0) and (stickmanstill._currentFrame == 1)) {
stickmanstill.gotoAndPlay("stickman");
} else if ((dx == 0) and (stickmanstill._currentFrame != 1)) {
stickmanstill.gotoAndPlay("stickmanstill");
}

this is the code i have got from your help, i would greatly appreciate it if you could tell me what I need to change and why, sorry for being such a pain.stop(); stop(); stop();

thestick
October 29th, 2002, 04:27 AM
i've changed the linkage properties and now when i load it up i get a walking stickman animation (stickman) and this in the output box

Generator is not enabled for this movie. C:\My Documents\jack\stickdude.swf

um, how do i enable the generator
?

pom
October 29th, 2002, 04:35 AM
Hang on!! :P

This will make it through the compilation:
stop();

function initGame() {
// create the stickman
attachMovie( "stickman", "stickmanstill",20) ;
stickman._x = 275;
stickman._y = 300;
}

function movestickman() {
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 10;
} else if (Key.isDown(Key.LEFT)) {
dx = -10;
} else {
// no movement
dx = 0;
}
// move the stickman and limit that movement
stickmanstill._x += dx;
if (stickmanstill._x < 30) stickmanstill._x = 30;
if (stickmanstill._x > 520) stickmanstill._x = 520;

// make the stickman run or stand still
if ((dx != 0) and (stickmanstill._currentFrame == 1)) {
stickmanstill.gotoAndPlay("stickman");
} else if ((dx == 0) and (stickmanstill._currentFrame != 1)) {
stickmanstill.gotoAndPlay("stickmanstill");
}
}Then you need to change your linkage names.

pom :)

thestick
November 10th, 2002, 08:32 AM
thanx for the code it works now, but one minor problem the stickman starts at the top of the screen and even when i change the "y" properties it won't move down, could you tell me how i can make it move please?

thestick
November 10th, 2002, 09:04 AM
i have now changed my code so it is more efficient but nothing seems to work could u please help?

stop ();
function initGame () {
// create the stickman
attachMovie("stickmanwalk", fred, 20);
fred._x = 275;
fred._y = 150;
attachMovie("stickmandance", jim, 20);
}
function movestickman () {
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 5;
} else if (Key.isDown(Key.LEFT)) {
dx = -5;
} else {
// no movement
dx = 0;
}
// move the stickman and limit that movement
fred._x += dx;
if (fred._x<30) {
fred._x = 30;
}
if (fred._x>520) {
fred._x = 520;
}
// make the stickman run or stand still
if (dx != 0) {
fred.gotoAndPlay("stickmanwalk");
} else {
jim._x = fred._x;
jim._y = fred._y;
jim.gotoAndPlay("stickmandance");
}
}