ForumsProgramming ForumAS3 KeyCode Tween Error Help

3 3437
kevinseven11
offline
kevinseven11
36 posts
Nomad

I have 2 errors on my code right now. im making it so when you press the up key my ball goes to x.(100) and y.(200). Im having refrencing issues i think.

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
import flash.events.KeyboardEvent.keyCode; // two of the same errors

var xMovement:Tween;
var yMovement:Tween;



function keypressed (keycode:KeyboardEvent):void {
if (KeyboardEvent.keycode == 38) { // error
xMovement = new Tween(tweenMC, "x", None.easeNone , tweenMC.x, x.(100) , .5, true);
yMovement = new Tween(tweenMC, "y", None.easeNone , tweenMC.y, y.(200) , .5, true);
}
}

  • 3 Replies
herofmb
offline
herofmb
30 posts
Nomad

I dont know for sure, since I'm kinda new to this, but when i need to use a keyCode I add the event and do like this:

//import keyboardEvent
import flash.events.KeyboardEvent;

//add the listener somewhere
addEventListener(KeyboardEvent.KEY_DOWN, keypressed);

function keypressed (e.KeyboardEvent):void
{
if (e.KeyCode == 38)
{
xMovement = new Tween(tweenMC, "x", None.easeNone , tweenMC.x, x.(100) , .5, true);
yMovement = new Tween(tweenMC, "y", None.easeNone , tweenMC.y, y.(200) , .5, true);
}
}

kevinseven11
offline
kevinseven11
36 posts
Nomad

that didnt work
hmm i couldnt think of anything else to try

PixelSmash
offline
PixelSmash
566 posts
Nomad

Could you post the exact errors you get? I don't know it from the top of my head, but I've seen my fair share of errors to know what to do occasionally.

Also, the code herofmb posted looks a whole lot better than what you first posted. You can't import the KeyboardEvent.keyCode - I believe that's only a property of a class, while you should import the class itself (KeyboardEvent).

Also, if you literally copy/pasted the code above, watch out for the function... instead of e.KeyboardEvent it should be e:KeyboardEvent, little typo there

Anyway... if you could post the errors you get now, I'll have another look!

Showing 1-3 of 3