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

时间:2011-11-22 20:28:03

标签: 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);

实际代码(可选阅读)

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

<?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行上进行,则构建不会中断。

其他信息(可选阅读)

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

临时解决方案(按要求)

我的项目如下:

        Model
     /        \
Viewer 1    Viewer 2

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

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

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

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

2 个答案:

答案 0 :(得分:0)

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

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

keep generated ActionScript

浏览到/ bin / generated以查看来源。

答案 1 :(得分:0)

我也遇到了这个问题,可以通过以下更改来修复它。 而不是例如:

model.textInput.text = "";

使用

var ti:TextInput = model.textInput;
ti.text = "";

这似乎有所帮助。

相关问题