EOSERV Forum > Programming > Movement Code in flash. (solved)
Topic is locked.
Page: << 1 >>
Movement Code in flash. (solved)
Author Message
Post #137281 Movement Code in flash. (solved)
Hello, I am Going to start making a maze game in flash with basic shapes but when i start to code, The frist thing MOVEMENT itdidnt try out that good. and getting the error access of undefined propertykeyboard. Please Help 


Or 

Edit: Changed name of movie clip.

package  
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
!!!!import flash.ui.Keyboard;!!! << Was missing this
public class CharacterArrowMovement extends MovieClip 
{
var myCharacter:character
var keys:Array = [ ] 
public function CharacterArrowMovement() 
{
myCharacter = new character
myCharacter.x = 33
myCharacter.y = 43
addChild(myCharacter)
myCharacter.addEventListener(Event.ENTER_FRAME, Update);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
}
function Update (e:Event):void
{
trace ("working")
if (keys[Keyboard.RIGHT])
      {
          myCharacter.x += 5;
      }
 
if (keys[Keyboard.LEFT])
{
myCharacter.x -= 5;
}
if (keys[Keyboard.UP]) 
{
myCharacter.y -= 5;
}
if (keys[Keyboard.DOWN])
{
myCharacter.y += 5;
}
}
function onKeyDown (e:KeyboardEvent):void
{
keys[e.keyCode] = true;
}
function onKeyUp (e:KeyboardEvent):void
{
keys[e.keyCode] = false;
}
}
}


Update: All i was missing was a Import, Thanks Apollo. :) 
14 years, 14 weeks ago
Page: << 1 >>
Topic is locked.
EOSERV Forum > Programming > Movement Code in flash. (solved)