キャラクターのコントロールを作成したい。残念ながら、エラー#1304が発生しました。
出力エラーは次のとおりです。
TypeError: Error #1034: Type Coercion failed: cannot convert class_Boy$ to
flash.display.MovieClip.
at class_Boy/mainJump()
at class_Boy/class_Boy_Move()
フラッシュは実行できますが、スペースバーを押すと、エラーが繰り返され、フラッシュが停止します。
犯人はMovieClip(boy_Class)
class_Boyのクラスの下にあると思います。あなたが解決策を見つけることができたら私を助けてください。ありがとう。
これはメインクラスです:
package
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.Timer;
import flash.text.*;
public class experimentingMain extends MovieClip
{
var count:Number = 0;
var myTimer:Timer = new Timer(10,count);
var classBoy:class_Boy;
var leftKey, rightKey, spaceKey, stopAnimation:Boolean;
public function experimentingMain()
{
myTimer.addEventListener(TimerEvent.TIMER, scoreUp);
myTimer.start();
classBoy = new class_Boy();
addChild(classBoy);
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressTheDamnKey);
stage.addEventListener(KeyboardEvent.KEY_UP, liftTheDamnKey);
}
public function pressTheDamnKey(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
leftKey = true;
stopAnimation = false;
}
if (event.keyCode == 39)
{
rightKey = true;
stopAnimation = false;
}
if (event.keyCode == 32)
{
spaceKey = true;
stopAnimation = true;
}
}
public function liftTheDamnKey(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
leftKey = false;
stopAnimation = true;
}
if (event.keyCode == 39)
{
rightKey = false;
stopAnimation = true;
}
if (event.keyCode == 32)
{
spaceKey = false;
stopAnimation = true;
}
}
public function scoreUp(event:TimerEvent):void
{
scoreSystem.text = String("Score : "+myTimer.currentCount);
}
}
}
これはclass_Boyのクラスです:
package
{
import flash.display.*;
import flash.events.*;
public class class_Boy extends MovieClip
{
var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
var mainSpeed:Number = 5;
var mainJumping:Boolean = false;
var jumpSpeedLimit:int = 40;
var jumpSpeed:Number = 0;
var theCharacter:MovieClip;
var currentX, currentY:int;
public function class_Boy()
{
this.x = 600;
this.y = 500;
addEventListener(Event.ENTER_FRAME, class_Boy_Move);
}
public function class_Boy_Move(event:Event):void
{
currentX = this.x;
if (MovieClip(parent).leftKey)
{
currentX += mainSpeed;
}
if (MovieClip(parent).rightKey)
{
currentX -= mainSpeed;
}
if (MovieClip(parent).spaceKey)
{
mainJump();
}
this.x = currentX;
this.y = currentY;
}
public function mainJump():void
{
currentY = this.y;
if(!mainJumping)
{
mainJumping = true;
jumpSpeed = jumpSpeedLimit*-1;
currentY += jumpSpeed;
} else {
if(jumpSpeed < 0){
jumpSpeed *= 1 - jumpSpeedLimit/250;
if(jumpSpeed > -jumpSpeedLimit/12){
jumpSpeed *= -2;
}
}
}
if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
{
jumpSpeed *= 1 + jumpSpeedLimit/120;
}
currentY += jumpSpeed;
if(currentY >= stage.stageHeight - MovieClip(class_Boy).height)
{
mainJumping = false;
currentY = stage.stageHeight - MovieClip(class_Boy).height;
}
}
}
}