Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
/t5/animate-discussions/typeerror-error-1034-type-coercion-failed-cannot-convert-flash-display-movieclip-64e6ca1-to-fla/m-p/3587337#M99178
Sep 17, 2013
Sep 17, 2013
My Error :-
TypeError: Error #1034: Type Coercion failed: cannot convert the_game@24d270b1 to flash.display.MovieClip.
at Game::Player/update()
at the_game_itself/update()
I tried as your suggestions. But unable to slove error.
Here is my
the_game_itself update function :-
public function update(evt:Event)
{
//******************
//Handle User Input
//******************
if (moveX > 0)
player.moveRight();
else if (moveX < 0)
player.moveLeft();
else if (moveX == 0)
player.stopMoving();
if (jump && !player.isInAir())
{
player.jump();
jump = false;
}
//******************
//Handle Game Logic
//******************
//Update lifts
for (var l=lifts.length - 1; l >= 0; l--)
{
lifts
.update();
}
//Update Player
player.update();
//Check for collisions
if (player.isInAir() && player.isFalling())
{
for (var i=bricks.length - 1; i >= 0; i--)
{
if (player.hitAreaFloor.hitTestObject(bricks
))
{
//Player landed on the brick
player.hitFloor(bricks
);
}
}
for (var j=lifts.length - 1; j >= 0; j--)
{
if (player.hitAreaFloor.hitTestObject(lifts
))
{
//Player landed on the lift
player.hitFloor(lifts
);
}
}
}
//Check for collisions
for (var k=coins.length - 1; k >= 0; k--)
{
if (player.hitTestObject(coins
))
{
//Player obtain a coin
playerScore += C.SCORE_PER_COIN;
//Remove the coin
mcGameStage.removeChild(coins
);
coins.splice(k,1);
}
}
if (player.notInScreen())
gameOver();
//******************
//Handle Display
//******************
//Display new Score
txtScorePlayer.text = String(playerScore);
}
Player update function :-
public function update()
{
//Move Horizontally
if (this.speedX < 0)
{
//Check if player should move
if (MovieClip(root).playerShouldMoveLeft())
{
this.x += this.speedX;
}
else
{
MovieClip(root).scrollGameObjects(-this.speedX);
}
}
else if (this.speedX > 0)
{
//Check if player should move
if (MovieClip(root).playerShouldMoveRight())
{
this.x += this.speedX;
}
else
{
MovieClip(root).scrollGameObjects(-this.speedX);
}
}
//Move Vertically
if (this.speedY < C.MAX_SPEED)
this.speedY += C.GRAVITY;
if (this.inAir)
this.y += this.speedY;
else
{
//Move the player as its floor moves
if (this.standingOn != null)
this.y = standingOn.y;
}
if (standingOn != null)
{
//Check if player has moved off the floor it stands on
if (!this.hitAreaFloor.hitTestObject(standingOn))
{
removeFloor();
}
}
//Animate
if (this.inAir)
{
if (this.currentLabel != C.PLAYER_JUMP)
this.gotoAndPlay(C.PLAYER_JUMP);
}
else if (this.speedX > 0)
{
if (this.currentLabel != C.PLAYER_RIGHT)
this.gotoAndPlay(C.PLAYER_RIGHT);
}
else if (this.speedX < 0)
{
if (this.currentLabel != C.PLAYER_LEFT)
this.gotoAndPlay(C.PLAYER_LEFT);
}
else
{
if (this.currentLabel != C.PLAYER_IDLE)
this.gotoAndPlay(C.PLAYER_IDLE);
}
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more