From: KungfuJoe1110 on
Ok, I've done some coding in C# and Java, so I know a little bit, and you
should be able to talk at me and I should get it.
Now:

Lingo is confusing me very badly. I've been trying to use JavaScript, but that
isn't working either. Only the very basic scripts will work for me (frame loops
and whatnot).

I'm trying to get a sprite to move when I press an arrow key, and am having
the darndest time. Does anyone know of a good tutorial (preferabally in
JavaScript) that explains this?

If so, please link me over, i'd greatly appreciate it.


Here's an example. I was reading the tutorial from this very site, and came
across this code:
function beginsprite() {


spr.pColor = color(random(0,255), random(0,255), random(0,255));

spr.pSpeed = 10;

trace("I made a random color and a constant speed for sprite " +
spr.spriteNum);

}

When I attached it to a sprite (by drawing a circle on the stage,
right-clicking and going to its script, and posting it), nothing happened. If
I'm understanding correctly, among other things, the color should change.
So I tried attaching it to the frame by doing this:
function enterFrame(me) {
beginsprite(5);
}

function exitFrame(me) {
_movie.go(_movie.frame)
}

function beginsprite(_movie.cast.sprite spr) {


spr.pColor = color(random(0,255), random(0,255), random(0,255));

spr.pSpeed = 10;

trace("I made a random color and a constant speed for sprite " +
spr.spriteNum);

}

but that didn't work either.

Please help me to understand this.

Thank you for your time
KFJ

From: Lukewig on
Hi,

Not sure where you got that code from, but it looks incomplete. Adding the
following code to a 'behaviour' on a sprite should work (note I am defining
'spr' before addressing it). I've also added some code showing how you might
check if an arrow key is pressed every enterframe, and move the sprite
accordingly:




function beginsprite() {
// get ref to sprite object
spr= sprite(this.spriteNum);
// do something to the object
spr.foreColor = color(random(0,255), random(0,255), random(0,255));

trace("I made a random color and a constant speed for sprite " +
spr.spriteNum);

}

function enterFrame() {
if ( _key.keyPressed(123)) {
spr.locH --
}
if ( _key.keyPressed(124)) {
spr.locH ++
}
}