How to do this XML declaration in Flex4 - apache-flex

I have a dataProvider that's defined with mx:XML like this.
<mx:dataProvider>
<mx:XML format="e4x">
<root label="All Items">
<morning label="Evening" type="check" />
<evening label="Evening" type="check" />
<night label="Night" type="check" />
</root>
</mx:XML>
</mx:dataProvider>
This doesn't seem to be a valid option anymore with the new spark architecture. Can someone suggest how this can be done? I thought if I put in Declarations, it would work, but doesn't seem to be the case.

Try:
<fx:XML>
...
</fx:XML>

Related

Enabling component error 1009

I want to enable a linkbar component. When I run the application and try to look for data into the linkbar I get error 1009: impossible to acess property or method of a null object reference. How can I enable a component in flex so that to avoid error 1009? Any help would be appreciated...
<mx:LinkBar dataProvider="myViewStack" enabled="true" activate="true"/>
<mx:ViewStack id = "myViewStack" width="624" height="212" enabled="true">
<mx:Canvas id="canvas3" label="Financement" enabled="true" >
<mx:Label x="38" y="10" text="Code Fin."/>
<mx:Label x="19" y="36" text="Fond propre" enabled="true"/>
</mx:Canvas>
</mx:ViewStack>
Check if "myViewStack" is initialized or not
<mx:LinkBar dataProvider="{myViewStack}" enabled="true"/>

How can I stop a FlexNativeMenu with keyEquivalents from stealing my keystrokes?

I have a native menu item with a shortcut for a simple letter like "F".
<s:menu>
<mx:FlexNativeMenu id="mainMenu"
dataProvider="{menuData}"
labelField="#label"
keyEquivalentField="#keyEquivalent"
showRoot="false" />
</s:menu>
<fx:Declarations>
<fx:XML format="e4x" id="menuData">
<root>
<menuitem label="Edit">
<menuitem label="Frame Selection" keyEquivalent="f"/>
</menuitem>
</root>
</fx:XML>
</fx:Declarations>
This works great, but when I try to type text in any textfield or textInput
anywhere in the app, I cant ever type f.
How can stop the menu from stealing my keyboard input ?
Perhaps a better pattern to menu accelerators would use the control key, such as CTRL+F in your example.
Your menuitem would therefore include controlKey="true"
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:menu>
<mx:FlexNativeMenu id="mainMenu"
dataProvider="{menuData}"
labelField="#label"
keyEquivalentField="#keyEquivalent"
showRoot="false" />
</s:menu>
<fx:Declarations>
<fx:XML format="e4x"
id="menuData">
<root>
<menuitem label="Edit">
<menuitem label="Frame Selection"
keyEquivalent="f"
controlKey="true" />
</menuitem>
</root>
</fx:XML>
</fx:Declarations>
<s:TextInput />
</s:WindowedApplication>

Flex 4 Changing style options with states

I'm interested in finding out the best approach to this issue, it's not technically difficult but there must be an elegant solution.
Basically i have a form that features mostly text inputs, i would like to change the style of the input boxes based on the current state.
I can do this in the mxml on each input...
<s:TextInput text="label" borderColor.State1="0xFFFFFF" borderColor.State2="0x000000"/>
But that involves creating properties on every single item in the form.
There must be a better way of doing this without adding a property to each item?
Thanks!
You can use transitions and SetAction to set styles on multiple objects at the same time based on a new viewstate. This is a piece of an example from the SDK documentation:
.
<s:states>
<s:State name="Login" />
<s:State name="Register" />
</s:states>
<s:transitions>
<!-- Define the transition from the base state to the Register state.-->
<s:Transition id="toRegister" fromState="*" toState="Register">
<s:Sequence targets="{[loginPanel, registerLink, confirm, loginLink]}">
<s:RemoveAction />
<s:Fade />
<s:SetAction target="{loginPanel}" property="title" />
<s:SetAction target="{loginButton}" property="label" />
<s:SetAction target="{loginButton}" property="color" />
<s:Resize target="{loginPanel}"/>
<s:AddAction />
<s:Fade />
</s:Sequence>
</s:Transition>
<!-- Define the transition from the Register state to the base state.-->
<s:Transition id="toDefault" fromState="Register" toState="*">
<s:Sequence targets="{[loginPanel, registerLink,
confirm, loginLink]}">
<s:RemoveAction/>
<s:SetAction target="{loginPanel}" property="title"/>
<s:SetAction target="{loginButton}" property="label"/>
<s:SetAction target="{loginButton}" property="color"/>
<s:Resize target="{loginPanel}"/>
<s:AddAction/>
</s:Sequence>
</s:Transition>
</s:transitions>
You can just target everything in the sequence (instead using different targets for each SetAction) and use the 'value' property of the SetAction to set the values to what you want.

Flex error: could not resolve to a component implementation

I am trying to create a menu bar with the following items: File, Database, Navigate, Window. However, I am getting an error which I do not understand: Could not resolve <mx:XMLList> to a component implementation. Can anyone explain the error to me? My code is as follows:
`
<mx:XMLList id="topLevelMenu">
<menuitem label="File" />
<menuitem label="Database"/>
<menuitem label="Navigate"/>
<menuitem label="Window" />
</mx:XMLList>
<mx:MenuBar width="100%" height="20" labelField="#label" id="mainMenuBar" dataProvider="{topLevelMenu}" />`
I googled for it and found a lot problems which generate this error message. None of them seemed to fit my case. When is this error generated?
The error means, basically, that the compiler can't find a component.
In this case, XMLList is not in the mx namespace. You didn't show the code where you import namespaces, but I assume you're using the default.
I suggest creating your XMLList in ActionScript, not MXML. I believe something like this should work:
public var topLevelMenu : XML = <menuItems>
<menuitem label="File" />
<menuitem label="Database"/>
<menuitem label="Navigate"/>
<menuitem label="Window" />
</menuItems>;
Then somewhere, perhaps in a creationComplete Handler you can change this into an XMLList
var myList : XMLList = topLevelMenu.menuitem
This code is written in the browser and untested.

Flex/actionscript: Using dataDescriptor on an AdvancedDataGrid

I have a hierarchical data set that i would like to display in an advancedDataGrid. My data is a set of composed value objects that do not use the 'children' attribute. On a Tree control you can create a custom dataDescriptor to define which elements contain the children of the node. Can this be done on the datagrid as well?
Hierarchical data has a childrenField property that you can use to "tell" the control where should it look for branches.
http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_07.html
From Adobe live docs on AdvancedDataGrid examples, you can see that you can set the dataProvider of the AdvancedDataGrid to a GroupingCollection instance, in order to create some groups for your data. Going down the class hierarchy, there is HierarchicalData, which you need to use when setting your dataProvider on the AdvancedDataGrid. Example (sorry for using arrays instead of one XML):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Array id="dianaSerfes">
<mx:Object name="geen" surname="zod" />
</mx:Array>
<mx:Array id="xySerfs">
<mx:Object name="sdf" surname="sdfsdgd" />
</mx:Array>
<mx:Array id="johnSerfs">
<mx:Object name="jack" surname="the ripper" />
<mx:Object name="diana" surname="bloom" serfs="{dianaSerfes}"/>
</mx:Array>
<mx:Array id="myData">
<mx:Object name="xy" surname="zzz" serfs="{xySerfs}" />
<mx:Object name="blue" surname="zed" />
<mx:Object name="John" surname="smith" serfs="{johnSerfs}" />
</mx:Array>
<mx:AdvancedDataGrid width="100%" height="100%">
<mx:dataProvider>
<mx:HierarchicalData id="hd" source="{myData}" childrenField="serfs" />
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" />
<mx:AdvancedDataGridColumn dataField="surname" />
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>

Resources