1067: Implicit coercion of a value of type theplayclass to an unrelated type main

Posted by Minelava on Stack Overflow See other posts from Stack Overflow or by Minelava
Published on 2013-06-30T04:16:54Z Indexed on 2013/06/30 4:21 UTC
Read the original article Hit count: 168

I need help because I want to create a gameover screen that display score. However, there's an error that prevent me from transferring the score from theplayclass.as to thegameoverclass.as. Are there ways to pass a value to another movieclip without causing any errors.

I refer the source code from this website : http://www.emanueleferonato.com/2008/12/17/designing-the-structure-of-a-flash-game-as3-version/

Here's the error

C:\Users\xxx\Downloads\Migrate\test\theplayclass.as, Line 54, Column 41 1067: Implicit coercion of a value of type theplayclass to an unrelated type main.

main.as

 package  
 {

 import flash.display.MovieClip;
 import flash.events.Event;

public class main extends MovieClip
{
    public var playClass:theplayclass;
    public var gameOverClass:thegameoverclass;

    public function main() 
    {
        showWin();

    }

    public function showWin()
    {           
        playClass = new theplayclass(this);
        addChild(playClass);            
    }

    public function showGameOver()
    {
        gameOverClass = new thegameoverclass(this);
        addChild(gameOverClass);

        removeChild(playClass);
        playClass = null;
    }
    }
}

theplayclass.as

 package  
 {
import flash.display.MovieClip;
import flash.events.*;

public class theplayclass extends MovieClip 
{
    private var mainClass:main;
    var gameScore:Number;
    var gameOverScore:thegameoverclass;

    public function theplayclass(passedClass:main)
    {           
        mainClass = passedClass;

        scoreText.text ="0";

        gameScore = 0;



        win.addEventListener(MouseEvent.CLICK, showwinFunction);
        next.addEventListener(MouseEvent.CLICK, showgameoverFunction);

        addEventListener(Event.ADDED_TO_STAGE, addToStage);
        addEventListener(Event.ENTER_FRAME, changeScore);

    }

    public function addToStage(e:Event):void
    {
        this.x = 0;
        this.y = 0;
    }

    private function showwinFunction(e:MouseEvent):void
    {
        gameScore+=50;
    }

    private function changeScore(e:Event):void
    {
        scoreText.text =""+gameScore;
    }


    public function showgameoverFunction(e:MouseEvent)
    {
        mainClass.showGameOver();

        gameOverScore = new thegameoverclass(this);
        gameOverScore.setTextScore(gameScore);

    }

    }
 }

thegameoverclass.as

package  
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.*;

public class thegameoverclass extends MovieClip 
{
    var mainClass:main;
    var scorePoints:Number;

    public function thegameoverclass(passedClass:main) 
    {
        mainClass = passedClass;
        finalScore.text = "test";
    }

    public function setTextScore(textToSet:Number)
    {
        finalScore.text = ""+scorePoints;
    }

    }

  }

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about oop