Столкнулся со странной и новой для меня проблемой. Я пытаюсь создать слушатель в классе, а меня ругают, что я не переопределил метод, но переопределять нечего, класс наследуется от мувика, где только картинка раст и усё. Конечно можно просто назвать иначе и всё нормально, но хочу понять откуда проблема появилась, в других классах, в которых теже события, теже названия функций всё нормально и отлично работает.
Код AS3:
package ClassGame.Object.PointerAndRoundSpeed
{
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import EventClass.UserEvent;
import Singleton.SpeedWorld.SpeedWorld.SpeedWorld;
import Singleton.SpeedWorld.SpeedWorldSingleton;
public class PointerAndRoundSpeed extends roundSpeed_mc
{
public function PointerAndRoundSpeed()
{
this.scaleX = 0.5;
this.scaleY = 0.5;
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private var pointerSpeed:pointerSpeed_mc = new pointerSpeed_mc();
private function init(e:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, init);
this.addEventListener(Event.REMOVED_FROM_STAGE, removeInit);
this.x = stage.stageWidth / 2;
this.y = -stage.stageHeight * 0.11;
if (pointerSpeed.stage == null)
{
pointerSpeed.scaleX = this.width / pointerSpeed.width;
this.addChild(pointerSpeed);
}
pointerSpeed.rotation = Math.random() * 360;
this.addEventListener(Event.ENTER_FRAME, pointUpdate);
stage.addEventListener(UserEvent.PAUSE, pause);
stage.addEventListener(UserEvent.PLAY, play);
}
private function play(e:UserEvent):void
{
}
private function pause(e:UserEvent):void
{
}
/**
* pointUpdate() поведение при старте
*/
private var stopBooleanRoundSpeed:Boolean = true;
private var quantityRoundSpeed:int = 0;
private function pointUpdate(e:Event):void
{
if (stopBooleanRoundSpeed)
{
if (this.y < stage.stageHeight / 2)
{
this.y += stage.stageHeight * 0.05;
if (this.y >= stage.stageHeight / 2)
{
this.y = stage.stageHeight / 2;
stopBooleanRoundSpeed = false;
}
}
}
else
{
if (quantityRoundSpeed <= 10)
{
this.y -= stage.stageHeight * 0.012;
quantityRoundSpeed++;
}
else if ((quantityRoundSpeed > 10) && (quantityRoundSpeed <= 20))
{
this.y += stage.stageHeight * 0.012;
quantityRoundSpeed++;
}
else if ((quantityRoundSpeed > 20) && (quantityRoundSpeed <= 25))
{
this.y -= stage.stageHeight * 0.01;
quantityRoundSpeed++;
}
else if ((quantityRoundSpeed > 25) && (quantityRoundSpeed <= 30))
{
this.y += stage.stageHeight * 0.01;
quantityRoundSpeed++;
}
else
{
this.removeEventListener(Event.ENTER_FRAME, pointUpdate);
this.addEventListener(Event.ENTER_FRAME, arrowUpdate);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownPointer, false, 1);
stage.addEventListener(MouseEvent.CLICK, clickPointer, false, 1);
stage.focus = stage;
}
}
}
/**
* постепенно увеличивает скорость вращения стрелки
*/
private var quantitySpeedPointer:Number = 3;
private function arrowUpdate(e:Event):void
{
pointerSpeed.rotation += quantitySpeedPointer;
if (quantitySpeedPointer < 10)
quantitySpeedPointer += 0.2;
}
private function clickPointer(e:Event):void
{
stage.removeEventListener(MouseEvent.CLICK, clickPointer);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownPointer);
this.removeEventListener(Event.ENTER_FRAME, arrowUpdate);
coefficientPointer();
stage.dispatchEvent(new UserEvent(UserEvent.START_FLAG_2, true, false));
e.stopImmediatePropagation();
stage.addEventListener(Event.ENTER_FRAME, endRoundSpeed);
}
private function keyDownPointer(e:KeyboardEvent):void
{
if (e.keyCode == 32)
{
stage.removeEventListener(MouseEvent.CLICK, clickPointer);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownPointer);
this.removeEventListener(Event.ENTER_FRAME, arrowUpdate);
coefficientPointer();
stage.dispatchEvent(new UserEvent(UserEvent.START_FLAG_2, true, false));
stage.addEventListener(Event.ENTER_FRAME, endRoundSpeed);
e.stopImmediatePropagation();
}
}
private var speedWorld:SpeedWorld;
private function coefficientPointer():void
{
speedWorld = SpeedWorldSingleton.getSpeedWorldSingleton.getSpeedWorld;
var coefficient:Number;
if (rotation < 0)
{
rotation *= -1;
if (rotation < 60)
coefficient = 5 / 6;
if ((rotation >= 60) || (rotation < 120))
coefficient = 1;
if ((rotation >= 120) || (rotation < 180))
coefficient = 5 / 6;
}
else
{
if (rotation < 60)
coefficient = 4 / 6;
if ((rotation >= 60) || (rotation < 120))
coefficient = 3 / 6;
if ((rotation >= 120) || (rotation < 180))
coefficient = 4 / 6;
}
speedWorld.setSpeedWorld = speedWorld.getMaxSpeedWorld * coefficient;
speedWorld.setCoefficientPointer = coefficient;
}
private var timer:Timer = new Timer(700);
private function endRoundSpeed(e:Event):void
{
stage.removeEventListener(Event.ENTER_FRAME, endRoundSpeed);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
}
private function timerHandler(e:Event):void
{
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, timerHandler);
this.addEventListener(Event.ENTER_FRAME, removeTimer);
}
private function removeTimer(e:Event):void
{
if (this.y > -stage.stageHeight * 0.2)
this.y = this.y - 15;
else
{
this.removeEventListener(Event.ENTER_FRAME, removeTimer);
stage.dispatchEvent(new UserEvent(UserEvent.REMOVE_POINTER_AND_ROUND_SPEED, true, false));
}
}
private function removeInit(e:Event):void
{
this.removeEventListener(Event.REMOVED_FROM_STAGE, removeInit);
this.removeEventListener(Event.ENTER_FRAME, pointUpdate);
this.removeEventListener(Event.ENTER_FRAME, arrowUpdate);
stage.removeEventListener(MouseEvent.CLICK, clickPointer);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownPointer);
stage.removeEventListener(Event.ENTER_FRAME, endRoundSpeed);
timer.removeEventListener(TimerEvent.TIMER, timerHandler);
this.removeEventListener(Event.ENTER_FRAME, removeTimer);
this.addEventListener(Event.ADDED_TO_STAGE, init);
stopBooleanRoundSpeed = true;
quantityRoundSpeed = 0;
quantitySpeedPointer = 3;
timer.stop();
}
}
}