2

I'm following hemanth sharma's excellent tutorial series on the starling framework. I more or less copied his code and made a few changes towards the game I have in mind. The code is 80% the same he used in his project. Nevertheless I'm encountering a strange error: "error 1067" it complains about the "implicit coercion" of supposedly unrelated types.

I browsed previous questions and discovered this one:

1067: Implicit coercion of a value of type Class to an unrelated type flash.display:DisplayObject

The error message I'm receiving is basically the same but unfortunately the solution does not apply to my problem. Moreover I'm getting this error in many interesting different flavours.

  1. I've got a custom event class called NavigationEvent that expands starling.events.Event. When the used tries to switch between the game screens this event is dispatched. Here's some code:

    import starling.events.Event;
    
    public class NavigationEvent extends Event
    

    it is dispatched like this:

    this.dispatchEvent(new NavigationEvent(NavigationEvent.CHANGE_SCREEN,{id:"play"},true));
    

    the error message says:

    Error 1067: Implicit coercion of a value of type events:NavigationEvent to an unrelated type starling.events:Event

    The code worked fine when I first wrote it but now, after I've changed another part of the program it is broken. I can't explain it. I extended NavigationEvent from starling.events.Event so the types are definitely not unrelated. I even ran the program like this. Admittedly the routine to switch between screens was no yet implemented but the event was fired without problems.

  2. In order to let the user trigger this event I added a button to the screen. It is starlings standard starling.display.Button;. The button is a member variable of my screen class

    private var playBtn:Button;
    

    However this line results in an error:

    playBtn=new Button(Assets.getAtlas().getTexture("play"));
    

    This time the error is even more outrageous:

    Error 1067: Implicit coercion of a value of type starling.textures:Texture to an unrelated type starling.textures:Texture

What can I do about this ?

4

1 回答 1

3

有时,当您在 Flash Builder 中打开两个 Flash Pro 项目,并且两个项目在代码路径中具有相同的目录时,您可能会遇到您遇到的错误。当您在其中一个项目中打开文件时会发生这种情况,但您正在编译和运行这两个项目(特别是如果您正在调试并设置了断点)。

我认为正在发生的事情是 FB 在同一个文件中编译,就好像它是一个不同的文件一样,因为它从文件打开的文件“延伸”并将其编译到它刚刚引用但未打开的文件中. 打开的文件扩展了项目中的基类,而不是项目中包含 fla/xfl 的基类。虽然我们知道它实际上是一个文件,但 FB 显然无法弄清楚。我认为你真的很轻松,因为我过去不得不采取真正英勇的措施来解决这个问题。

您可以通过将共享代码移出库项目来解决此问题,我认为这是工程师可能认为每个人都会这样做的场景。我认为他们无法(或至少没有)预见到历史 Flash 开发实践的交集以及将 FB 和 FP 一起使用的怪癖会导致此特定错误出现。

于 2012-11-03T21:28:17.347 回答