注意:我多次编辑了这个问题并重新格式化它以更好地说明这个问题。
问题
我的构建有问题。当我向代码中添加一个有效的语句时,它将不再符合,并且它会因来自无关文件的错误而失败。我在命令行中使用 ant 构建或使用 mxmlc 构建时遇到了这些问题。
将有效语句添加到 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);
实际代码(可选阅读)
工作代码 - 编译正常没有问题(可选阅读)
<?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>
损坏的代码 - 不编译因上述错误而失败(可选阅读)
<?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>
观察(选读)
该注释似乎并没有破坏构建,因为如果我输入较短的注释,则不会出现编译错误。例如,如果我用上面的评论代替此评论:
/*
This
is
going
to
break
it.
*/
构建不会中断。同样,如果我添加一个超过 4-5 行的 ArrayCollection 定义,构建将中断。但是,如果定义仅扩展到 1-2 行,则构建不会中断。
其他信息(选读)
临时解决方案(按要求)
我的项目是这样的:
Model
/ \
Viewer 1 Viewer 2
我有两个观众从同一个模型中潜水。他们都有对模型的引用,但他们没有对彼此的引用,并且模型没有对任一查看器的引用。
我注意到模型在 Viewer 1 中使用了一个常量。这导致在构建 Viewer 2 时构建了所有的 Viewer 1。我将常量从 Viewer 1 移到 Model(无论如何它确实应该在那里)并且我的项目成功构建,因为 Viewer 1 和 Viewer 2 不是同时构建的。
这将解决问题是有道理的,但这只是解决问题的一个症状。当我向 myLittleBox.mxml 添加注释时,我仍然很好奇是什么导致编译器在 ViewerMain.mxml 上失败。我想它现在仍然是个谜。
最佳答案
要诊断 MXML 代码生成问题,请通过向 Flex Compiler 附加编译器参数添加“-keep”来保留生成的 ActionScript。
这将使您能够从 MXML 标记查看编译器生成的 ActionScript。生成的类文件包括由编译器生成并用于构建 SWF 文件的 stub 和类。
浏览到/bin/generated 查看源代码。
关于apache-flex - 构建 Flex 的奇怪问题(由于正确代码上的无关错误而失败),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8233374/