构建Flex的奇怪问题(在正确的代码上出现无关的错误)

six*_*ude 5 apache-flex mxmlc

注意:我已多次编辑此问题并重新格式化以更好地证明问题.

问题

我的构建有问题.当我向代码添加一个有效的语句时,它将不再编译,并且它会因无关文件的错误而失败.我在命令行中遇到了使用ant构建或使用mxmlc构建这些问题.

将有效语句添加到myLittleBox.mxml将导致此错误.注意:

  • 所有错误都在ViewerMain.mxml中.此文件不是主mxml文件,但它是从主mxml文件引用的.
  • 在更改myLittleBox.mxml之前,ViewerMain.mxml没有编译错误
  • 没有与myLittleBox.mxml相关的错误
  • myLittleBox.mxml没有对ViewerMain的引用,只使用spark组件
  • ViewerMain.mxml没有对myLittleBox.mxml的直接引用.它的孩子的孩子的孩子会引用myLittleBox.mxml
  • 添加到myLittleBox.mxml的有效语句可能是很多东西(它们都会破坏它),包括注释.

什么可能导致这些错误?我该如何解决这些问题?非常感谢提示或一点点洞察力.

编译错误(可选阅读)

[mxmlc] Loading configuration file PATH_1\flex-config.xml
[mxmlc] PATH-3\ViewerMain.mxml(207):  Error: Access of possibly undefined property p through a reference with static type com.....
[mxmlc]                 if(model.InfoBox && model.InfoBox.p) 
[mxmlc] PATH-3\ViewerMain.mxml(209):  Error: Implicit coercion of a value of type com.....InfoBox to an unrelated type flash.display:DisplayObject.
[mxmlc]                     InfoBoxContainer.addChild(model.infoBox);
[mxmlc] PATH-3\ViewerMain.mxml(228):  Error: Call to a possibly undefined method toggleWin through a reference with static type com.....:InfoBox.
[mxmlc]                         model.InfoBox.toggleWin();                      
[mxmlc] PATH-3\ViewerMain.mxml(231):  Error: Call to a possibly undefined method createCallback through a reference with static type com.......:InfoBox.
[mxmlc]                         return model.InfoBox.createCallback(e);
[mxmlc] PATH-3\ViewerMain.mxml(243):  Error: Call to a possibly undefined method toggleWin through a reference with static type com.......:InfoBox.
[mxmlc]                         model.InfoBox.toggleWin();  
[mxmlc] PATH-3\ViewerMain.mxml(246):  Error: Call to a possibly undefined method createCallback2 through a reference with static type com.......:InfoBox.
[mxmlc]                         model.InfoBox.createCallback2(e);           
[mxmlc] PATH-3\ViewerMain.mxml(256):  Error: Call to a possibly undefined method onTitleClick through a reference with static type com..........:MapInfoBox.
[mxmlc]                     model.InfoBox.onTitleClick(e);
Run Code Online (Sandbox Code Playgroud)

实际代码(可选阅读)

工作代码 - 编译没问题(可选阅读)

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"
         >

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            private var thisWillNotBrakeIt:String = "Done breaking";

        ]]>
    </fx:Script>
    <s:VGroup>

        <s:Label text="Target:"/>
        <s:HGroup>
            <s:TextInput/>
            <s:Button label="..."/>
        </s:HGroup>

        <s:Label text="Action"/>
        <s:ComboBox/>

        <s:Label text="Address"/>
        <s:ComboBox/>

        <s:CheckBox label="Open in new window"/>

        <s:Label text="Parameters"/>
        <s:Label text="TODO: Insert AutoSizeTree Component here"/>
        <s:Button label="Edit (Change to image later)"/>

        <s:Label text="Animals"/>
        <s:ComboBox/>

    </s:VGroup>
</s:Group>
Run Code Online (Sandbox Code Playgroud)

代码损坏 - 编译失败并出现上述错误(可选阅读)

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"
         >

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            private var thisWillNotBrakeIt:String = "Done breaking";
            /*
                This 
                is 
                going
                to 
                break
                it.

                Interestingly it
                did not break it
                but I bet that 
                this line will break it.  

                Break break break.
            */
        ]]>
    </fx:Script>
    <s:VGroup>

        <s:Label text="Target:"/>
        <s:HGroup>
            <s:TextInput/>
            <s:Button label="..."/>
        </s:HGroup>

        <s:Label text="Action"/>
        <s:ComboBox/>

        <s:Label text="Address"/>
        <s:ComboBox/>

        <s:CheckBox label="Open in new window"/>

        <s:Label text="Parameters"/>
        <s:Label text="TODO: Insert AutoSizeTree Component here"/>
        <s:Button label="Edit (Change to image later)"/>

        <s:Label text="Animals"/>
        <s:ComboBox/>

    </s:VGroup>
</s:Group>
Run Code Online (Sandbox Code Playgroud)

观察(选修)

评论似乎没有打破构建,因为如果我放一个较短的注释没有编译错误.例如,如果我将以上评论替换为此评论:

        /*
            This 
            is 
            going
            to 
            break
            it.
        */
Run Code Online (Sandbox Code Playgroud)

构建不会破坏.类似地,如果我添加一个延伸超过4-5行的ArrayCollection定义,构建将会中断.但如果定义仅在1-2行上进行,则构建不会中断.

其他信息(可选阅读)

  • 使用Flex 4.0
  • Ant 1.7.0(?我想.不确定找到这个的最好方法.如果有人想要这个信息,我会的.)
  • Eclipse(Flash Builder).

临时解决方案(按要求)

我的项目看起来像这样:

        Model
     /        \
Viewer 1    Viewer 2
Run Code Online (Sandbox Code Playgroud)

我有两个观众正在偏离同一个模型.它们都具有对模型的引用,但它们没有对彼此的引用,并且模型没有对任一查看器的引用.

  • ViewerMain.mxml文件位于Viewer 1中.
  • 文件myLittleBox.mxml在Viewer 2中.

我注意到Model在Viewer 1中使用了一个常量.这导致在构建Viewer 2时构建了所有Viewer 1.我将常量从查看器1移动到模型(无论如何它应该在那里)并且我的项目成功构建,因为查看器1和查看器2没有同时构建.

这有助于解决问题,但这只是解决问题的症状.我仍然非常好奇当我向myLittleBox.mxml添加注释时,导致编译器在ViewerMain.mxml上失败的原因.我想现在仍然是个谜.

Jas*_*ges 0

要诊断 MXML 代码生成问题,请通过向 Flex 编译器附加编译器参数添加“-keep”来保留生成的 ActionScript。

这将使您能够查看编译器从 MXML 标记生成的 ActionScript。生成的类文件包括由编译器生成并用于构建 SWF 文件的存根和类。

保留生成的 ActionScript

浏览到 /bin/ generated 以查看源代码。