Показать сообщение отдельно
Старый 09.04.2010, 08:58
engineer_f_R вне форума Посмотреть профиль Отправить личное сообщение для engineer_f_R Найти все сообщения от engineer_f_R
  № 5  
Ответить с цитированием
engineer_f_R

Регистрация: Oct 2009
Сообщений: 53
Я делаю так:
Код AS3:
package 
{
	import flash.display.*;
	import flash.events.*;
	public class MainClass extends MovieClip
	{
		public var keyboardControl:KeyboardControl = new KeyboardControl ();
		var hero:HeroBase = new HeroBase();
		var heroM:HeroMove = new HeroMove();
 
		public function MainClass ()
		{
			stage.addChild(keyboardControl);
			keyboardControl.addEvents();
 
			stage.addChild(hero);
			hero.setCoordinates(50,50);
 
			stage.addChild(heroM);
			heroM.addEvents();
		}
}
 
}
Код AS3:
package {
	import flash.display.*;
	import flash.ui.*;
	import flash.events.*;
	import flash.events.KeyboardEvent;
 
	public class KeyboardControl extends MovieClip {
 
		public var leftKeyIsDown:Boolean=false;
		public var rightKeyIsDown:Boolean=false;
		public var upKeyIsDown:Boolean=false;
		public var downKeyIsDown:Boolean=false;
		var keyPressed:int;
		var keyReleaseCode:int;
 
		public function KeyboardControl():void {
 
 
		}
 
		public function addEvents(){
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressFunction);
			stage.addEventListener(KeyboardEvent.KEY_UP, keyReleaseFunction);
 
		}
 
 
 
		public function keyPressFunction(e:KeyboardEvent):void {
 
			keyPressed=e.keyCode;
 
			if (keyPressed==Keyboard.RIGHT) {
				rightKeyIsDown=true;
			}
			if (keyPressed==Keyboard.LEFT) {
				leftKeyIsDown=true;
			}
			if (keyPressed==Keyboard.UP) {
				upKeyIsDown=true;
			}
			if (keyPressed==Keyboard.DOWN) {
				downKeyIsDown=true;
			}
		}
 
 
		function keyReleaseFunction(e:KeyboardEvent):void {
			keyReleaseCode=e.keyCode;
			if (keyReleaseCode==Keyboard.RIGHT) {
				rightKeyIsDown=false;
			}
			if (keyReleaseCode==Keyboard.LEFT) {
				leftKeyIsDown=false;
			}
			if (keyReleaseCode==Keyboard.UP) {
				upKeyIsDown=false;
			}
			if (keyReleaseCode==Keyboard.DOWN) {
				downKeyIsDown=false;
			}
		}
	}
 
}
Код AS3:
package 
{
	import flash.display.*;
	import flash.ui.Keyboard;
	import flash.events.*;
 
	public class HeroMove extends MovieClip
	{
		public function HeroMove()
		{
 
		}
 
		public function addEvents(){
			stage.addEventListener(Event.ENTER_FRAME, everyFrame)
 
		}
 
 
		public function everyFrame(){
 
			if( keyboardControl.leftKeyIsDown){}
			if( keyboardControl.rightKeyIsDown){}
			if( keyboardControl.upKeyIsDown){}
			if( keyboardControl.downKeyIsDown){}
 
		}
 
	}
 
}
и при компиляции мне ругаются что keyboardControl.leftKeyIsDown - неизвестное свойство. Как мне его сделать известным?