Flash actionscript guidance needed?
I am developing a flash games in which a letter symbol flies from right side of the screen and ends at left i need to process some keyboard events i.e when a开发者_JAVA技巧 letter is on the vertical bar the letter should stop there. Can any one guide me how can i achieve this
Abdul Khaliq
An easy approach is to put the created "letters" in an Array and call an update function (TimerEvent.TIMER or Event.ENTER_FRAME) wich moves/animates the letters. If the letter is inside the vertical bar (in range of x) and the correct key is pressed then you just lock it there.
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpHandler);
private function onKeyUpHandler(event : KeyboardEvent) : void
{
for(var i : int = 0 ; i < _letterList.length ; i++)
{
if(isInRange(_letterList[i]))
{
if(_letterList[i].validateKey(event.keyCode))
{
// lock on position and skip further updates
}
}
}
}
精彩评论