Flash 5, move character help

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

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:

Well, what is that code doing, Thestick? I mean, what’s the problem?

pom :slight_smile:

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:

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 …

Did you try to replace stickman by stickmanstill in your code?

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

Well, it’s 10:20 pm here… :stuck_out_tongue:

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)

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

That was the problem… :stuck_out_tongue:

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?

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? :-\

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

Put a } at the end of your function…

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.

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.[SIZE=1]stop();[/SIZE] [FONT=arial]stop();[/FONT] [FONT=arial]stop();[/FONT]

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
?

Hang on!! :stuck_out_tongue:

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 :slight_smile:

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?