添加 Child 时出现 Starling 奇怪错误

Starling Weird Error when Adding Child

我正在跟随 Lynda 教程使用 Starling 构建 Flash 游戏 在某些时候我遇到了非常奇怪的错误。

我有一个 Class 背景包 objects:

package objects
{   
import core.Assets;

import starling.display.Image;
import starling.display.Sprite;

public class Background extends Sprite
{
    private var sky1:Image;
    private var sky2:Image;

    public function Background()
    {
        sky1 = new Image(Assets.skyTexture);
        addChild(sky1);

        sky2 = new Image(Assets.skyTexture);
        sky2.y = -800;
        addChild(sky2);
    }

    public function update():void
    {
        sky1.y += 4;
        if(sky1.y == 800)
        {
            sky1.y = -800;
        }
        sky2.y +=4;
        if(sky2.y == 800)
        {
            sky2.y = -800;
        }
    }
}
}

和菜单 class 包状态:

package states
{
import flash.display.Sprite;

import core.Game;

import interfaces.IState;

import objects.Background;

import starling.events.Event;


public class Menu extends Sprite implements IState
{

    private var game:Game;
    private var background:Background;


    public function Menu(game:Game)
    {
        this.game = game;
        addEventListener(Event.ADDED_TO_STAGE, init);

    }

    private function init(event:Event):void
    {
        background = new Background();
        addChild(background);

    }

    public function update():void
    {
    }

    public function destroy():void
    {
    }
}
}

上线

addChild(background); I get this weird Error and I'm sure there's no any Errors in any other Class

Implicit coercion of a value of type Background to an unrelated type DisplayObject. Menu.as /Spacer/src/states  line 31 Flex Problem

当我在没有这条线的情况下进行调试时,我没有得到任何错误。

您的 Menu class 扩展了 flash.display.SpriteBackground class 扩展了 starling.display.SpriteMenu class 应该是八哥 Sprite.

的延伸