构建Flex的奇怪问题(在正确的代码上出现无关的错误)
注意:我已多次编辑此问题并重新格式化以更好地证明问题.
问题 我的构建有问题.当我向代码添加一个有效的语句时,它将不再编译,并且它会因无关文件的错误而失败.我在命令行中遇到了使用ant构建或使用mxmlc构建这些问题. 将有效语句添加到myLittleBox.mxml将导致此错误.注意: >所有错误都在ViewerMain.mxml中.此文件不是主mxml文件,但它是从主mxml文件引用的. 题 什么可能导致这些错误?我该如何解决这些问题?非常感谢提示或一点点洞察力. 编译错误(可选阅读) [mxmlc] Loading configuration file PATH_1flex-config.xml [mxmlc] PATH-3ViewerMain.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-3ViewerMain.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-3ViewerMain.mxml(228): Error: Call to a possibly undefined method toggleWin through a reference with static type com.....:InfoBox. [mxmlc] model.InfoBox.toggleWin(); [mxmlc] PATH-3ViewerMain.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-3ViewerMain.mxml(243): Error: Call to a possibly undefined method toggleWin through a reference with static type com.......:InfoBox. [mxmlc] model.InfoBox.toggleWin(); [mxmlc] PATH-3ViewerMain.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-3ViewerMain.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.,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行上进行,则构建不会中断. 其他信息(可选阅读) >使用Flex 4.0 临时解决方案(按要求) 我的项目看起来像这样: Model / Viewer 1 Viewer 2 我有两个观众正在偏离同一个模型.它们都具有对模型的引用,但它们没有对彼此的引用,并且模型没有对任一查看器的引用. > ViewerMain.mxml文件位于Viewer 1中. 我注意到Model在Viewer 1中使用了一个常量.这导致在构建Viewer 2时构建了所有Viewer 1.我将常量从查看器1移动到模型(无论如何它应该在那里)并且我的项目成功构建,因为查看器1和查看器2没有同时构建. 这有助于解决问题,但这只是解决问题的症状.我仍然非常好奇当我向myLittleBox.mxml添加注释时,导致编译器在ViewerMain.mxml上失败的原因.我想现在仍然是个谜. 解决方法
要诊断MXML代码生成问题,请通过向Flex Compiler添加“-keep”其他编译器参数来保留生成的ActionScript.
这将使您能够从MXML标记中查看编译器生成的ActionScript.生成的类文件包括由编译器生成并用于构建SWF文件的存根和类. 浏览到/ bin / generated以查看源. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |