构建 Flex 时出现奇怪的问题(在正确代码上出现不相关错误而失败)

发布于 2024-12-17 18:13:36 字数 6177 浏览 3 评论 0原文

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

问题

我的构建存在问题。当我向代码中添加有效语句时,它将不再符合并且由于来自不相关文件的错误而失败。我在命令行上使用 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 生成器)。

临时解决方案(根据请求)

我的项目如下所示:

        Model
     /        \
Viewer 1    Viewer 2

我有两个来自同一模型的查看器。它们都具有对模型的引用,但彼此之间没有引用,并且模型没有对任一查看器的引用。

  • 文件 ViewerMain.mxml 位于查看器 1 中。
  • 文件 myLittleBox.mxml 位于查看器 2 中。

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

这是有道理的,这可以解决问题,但这只是解决问题的症状。当我向 myLittleBox.mxml 添加注释时,我仍然很好奇是什么导致编译器在 ViewerMain.mxml 上失​​败。我想这暂时还是个谜。

Note: I have edited this question multiple times and reformatted it to better illistrate the question.

Problem

I am having a problem with my build. When I add a valid statement to the code it will no longer complie and it fails with errors from an unrelated file. I experience these issues building with ant or building with mxmlc on the command line.

Adding a valid statement to an myLittleBox.mxml will cause this error. Note that:

  • All the errors are in ViewerMain.mxml. This file is not the main mxml file but it is referenced from the main mxml file.
  • Before changing myLittleBox.mxml ViewerMain.mxml had no compile errors
  • There are no errors related to myLittleBox.mxml
  • myLittleBox.mxml has no references to ViewerMain and only uses spark components
  • ViewerMain.mxml has no direct references to myLittleBox.mxml. Its children's children's children would have a reference to myLittleBox.mxml
  • The valid statement added to myLittleBox.mxml could be many things (they all break it) including a comment.

Question

What could be causing these errors? How can I fix them? Hints or little nuggets of insight are greatly appreciated.

Compilation Error (Optional Reading)

[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);

Actual Code (Optional Reading)

Working Code - Compiles fine no issues (Optional Reading)

<?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>

Broken Code - Does not compile fails with above errors (Optional Reading)

<?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>

Observations (Optional Reading)

The comment does not seem to be breaking the build since if I put in a shorter comment there are no compilation errors. For example if I subsitute the above comment for this comment:

        /*
            This 
            is 
            going
            to 
            break
            it.
        */

the build will not break. Simularly if I add an ArrayCollection definition that stretches over 4-5 lines the build will break. But if the definition is streched over just 1-2 lines the build will not break.

Other Info (Optional Reading)

  • Using Flex 4.0
  • Ant 1.7.0 (? I think. Not sure the best way to find this out. I will if anyone wants the info).
  • Eclipse (Flash Builder).

Temporary Solution (By Request)

My project looks like this:

        Model
     /        \
Viewer 1    Viewer 2

I have two viewers that are diven off the same model. They both have references to the model but they do not have references to eachother and the model does not have a reference to either viewer.

  • The file ViewerMain.mxml is in Viewer 1.
  • The file myLittleBox.mxml is in Viewer 2.

I noticed that the Model was using a constant in Viewer 1. This was causing all of Viewer 1 to be built when Viewer 2 is built. I moved the constant from Viewer 1 to the the Model (where it really should have been anyways) and my project built successfully since Viewer 1 and Viewer 2 were not being built at the same time.

It makes sense that this would resolve the issue however this is just resolving a symptom of the issue. I am still very curious what was causing the the compiler to fail on ViewerMain.mxml when I add a comment to myLittleBox.mxml. I guess that it will remain a mystery for now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睫毛上残留的泪 2024-12-24 18:13:36

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

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

keep generated ActionScript

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

To diagnose MXML code generation issues, keep generated ActionScript by adding "-keep" to the Flex Compiler additional compiler arguments.

This will enable you to view the compilers generated ActionScript from your MXML markup. The generated class files include stubs and classes that are generated by the compiler and used to build the SWF file.

keep generated ActionScript

Browse to /bin/generated to view source.

廻憶裏菂餘溫 2024-12-24 18:13:36

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

model.textInput.text = "";

使用

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

这似乎有帮助。

I also faced this issue and could fix it with following change.
Instead of e.g. :

model.textInput.text = "";

use

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

This seems to help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文