sixtyfootersdude
sixtyfootersdude

Reputation: 27241

Strange issue building Flex (fails with unrelated errors on correct code)

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:

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)

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.

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.

Upvotes: 5

Views: 1195

Answers (2)

majoshi1
majoshi1

Reputation: 116

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.

Upvotes: 0

Jason Sturges
Jason Sturges

Reputation: 15955

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.

Upvotes: 0

Related Questions