Chad 2010-08-14
I'm now getting into the latest version of Flex, that is, Flex 4. There are a lot of new features comparing to Flex 3, all of which are very handy to developers.
In Flash Builder 4, when I tried to create a MXML component and instantiate it in the main MXML application, I found that the "Outline" explorer is not displaying the correct tree view anymore, instead it displayed excalmatory marks for each of the components' icon:
And when I switched to the design view in the MXML editor, it failed to render the preview and showed an error message "The default property contents must be contiguous":
However, when I compiled and run the application, everything looked OK. I think this was just an error for the Flash Builder 4 failing to parse and render the outline and preview. The code which was generating such error looks like this:
- <?xml version="1.0" encoding="utf-8"?>
- <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx"
- xmlns:components="components.*">
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <s:layout>
- <s:VerticalLayout horizontalAlign="center" paddingTop="20"/>
- </s:layout>
- <!-- shorthand MXML bindings -->
- <s:TextInput id="sourceText" text="some value"/>
- <s:Label text="{sourceText.text}"/>
- <!-- two-way bindings -->
- <s:TextInput id="input1" text="@{input2.text}"/>
- <s:TextInput id="input2"/>
- <!-- Using <fx:Binding> -->
- <s:TextInput id="sourceText2" text="some value 2"/>
- <s:Label id="destinationText"/>
- <fx:Binding source="sourceText2.text" destination="destinationText.text"/>
- <!-- Instantiate a MXML component -->
- <components:MyComponent id="comp1"/>
- </s:Application>
As the error message said, the visual componets (default property contents) must be contiguous. So I tried to move the "fx:Binding" tag to just behind the "fx:Declaration" tag, then the error went away.
- <?xml version="1.0" encoding="utf-8"?>
- <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx"
- xmlns:components="components.*">
- <fx:Declarations>
- <!-- Place non-visual elements (e.g., services, value objects) here -->
- </fx:Declarations>
- <fx:Binding source="sourceText2.text" destination="destinationText.text"/>
- <s:layout>
- <s:VerticalLayout horizontalAlign="center" paddingTop="20"/>
- </s:layout>
- <!-- shorthand MXML bindings -->
- <s:TextInput id="sourceText" text="some value"/>
- <s:Label text="{sourceText.text}"/>
- <!-- two-way bindings -->
- <s:TextInput id="input1" text="@{input2.text}"/>
- <s:TextInput id="input2"/>
- <!-- Using <fx:Binding> -->
- <s:TextInput id="sourceText2" text="some value 2"/>
- <s:Label id="destinationText"/>
- <!-- Instantiate a MXML component -->
- <components:MyComponent id="comp1"/>
- </s:Application>
Note that the "s:layout" from the spark library is also a non-visual component, so it can't be placed between any of the visual components neither, otherwise the same error would occur.