I need the label to be indented. Setting de properties top, bottom, left don't work.
<?xml version="1.0" encoding="utf-8"?>
<s:DefaultGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" top="10" bottom="10"
left="{data != null ? left = (data.niveau-1) * 20 : ''}">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
override public function prepare(willBeRecycled:Boolean):void{
if(data != null){
label = data.tekst;
styleName= 'niveau'+data.niveau;
toolTip=data.hulptekst;
}
}
]]>
</fx:Script>
</s:DefaultGridItemRenderer>
I think the best way to take control over alignment is to integrate your components into a Group.
Here is an effect you can achieve:
Here is the code:
//App
<?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" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var myDP:ArrayCollection = new ArrayCollection([
{myfield:"Hello", niveau:3},
{myfield:"World", niveau:7},
{myfield:"!!!", niveau:5}
]);
]]>
</fx:Script>
<s:DataGrid id="myDG" x="20" y="20" height="120" dataProvider="{myDP}" editable="true">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="myfield" headerText="My Field" width="170" itemRenderer="renderers.CustomRenderer"/>
<s:GridColumn dataField="myfield" headerText="My Field" width="170"/>
</s:ArrayList>
</s:columns >
</s:DataGrid>
</s:Application>
//Renderer
<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<fx:Script>
<![CDATA[
override public function prepare(hasBeenRecycled:Boolean):void {
lblData.text = data[column.dataField]
}
]]>
</fx:Script>
<s:Group width="100%" height="100%">
<s:Label id="lblData" top="9" left="{data != null ? (data.niveau - 1) * 20 : 0}"/>
</s:Group>
</s:GridItemRenderer>
Related
I am using a datagroup for displaying XML data. When I am using default item renderer the nodes are displaying, but when I try with my own itemrenderer, it fails. Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
<s:layout>
<s:VerticalLayout paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
]]>
</fx:Script>
<fx:Declarations>
<fx:XML id="DataXml" source="Data.xml"/>
</fx:Declarations>
<s:Label text="Start"/>
<s:Scroller>
<s:DataGroup width="100%" height="100%" itemRenderer="views.DataItemRenderer"
dataProvider="{new XMLListCollection(DataXml.children())}" >
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:DataGroup>
</s:Scroller>
<s:Label text="end"/>
</s:View>
Item renderer::::
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" >
<fx:Declarations>
<s:HGroup width="100%">
<s:Label id="txtFirstName" text="Name::"/>
<s:Label id="locationTxt" text="LOcation::"/>
<s:Label id="packTxt" text="Package::"/>
<s:Label id="experienceTxt" text="Experience::"/>
<s:Label id="designationTxt" text="Designation::"/>
</s:HGroup>
</fx:Declarations>
<fx:Script>
<![CDATA[
override public function set data(value:Object):void {
txtFirstName.text += value.firstName;
locationTxt.text += value.location;
packTxt.text += value.pack;
experienceTxt.text += value.experience;
designationTxt.text += value.designation;
}
]]>
</fx:Script>
</s:ItemRenderer>
XML File::
<?xml version="1.0" encoding="UTF-8"?>
<data>
<employee>
<firstname>Bujji</firstname>
<location>Hyderabad</location>
<pack>28000</pack>
<experience>1year</experience>
<designation>ASE</designation>
</employee>
<employee>
<firstname>Tanuja</firstname>
<location>Hyderabad</location>
<pack>25000</pack>
<experience>2Year</experience>
<designation>ASE</designation>
</employee>
<employee>
<firstname>Sarath</firstname>
<location>Banglore</location>
<pack>12000</pack>
<experience>1Year</experience>
<designation>JSE</designation>
</employee>
</data>
The issue is in the ItemRenderer file. You've got your s:HGroup inside the fx:Declerations tag. Place it outside and it should be fine.
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" >
<s:HGroup width="100%">
<s:Label id="txtFirstName" text="Name::"/>
<s:Label id="locationTxt" text="LOcation::"/>
<s:Label id="packTxt" text="Package::"/>
<s:Label id="experienceTxt" text="Experience::"/>
<s:Label id="designationTxt" text="Designation::"/>
</s:HGroup>
</s:ItemRenderer>
NB: The declerations tag is for non-visual elements. (See adobe docs)
The following item renderer works for me:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
width="100%" height="20">
<s:HGroup width="100%">
<s:Label id="txtFirstName"/>
<s:Label id="locationTxt"/>
<s:Label id="packTxt"/>
<s:Label id="experienceTxt"/>
<s:Label id="designationTxt"/>
</s:HGroup>
<fx:Script>
<![CDATA[
override public function set data(value:Object):void {
super.data = value;
trace("Name: " + value.firstname);
txtFirstName.text = "Name: " + value.firstname;
locationTxt.text = "Location: " + value.location;
packTxt.text = "Package: " + value.pack;
experienceTxt.text = "Experience: " + value.experience;
designationTxt.text = "Designation: " + value.designation;
}
]]>
</fx:Script>
</s:ItemRenderer>
I am developing a desktop air application in flex. I have 2 mxml (one mxml is windowedapplication and another one in mxml group). I want to navigate from one mxml file (login.mxml) to another (nextpage.mxml).
How can I acheive this?
login.mxml:
<?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">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>`enter code here`
<![CDATA[
public function onLogin()
{
// What code should i use to navigate to another mxml page i.e nextpage.mxml
}
]]>
</fx:Script><s:Button id="btn" name="Login" click="onLogin()"/</s:WindowedApplication>
nextpage.mxml:
<?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" width="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label text="Login Success/></s:Group>
It would be good to implement the main application as a coordinator of the application's state.
In this case you can use the ViewStack component, which has Login and NextPage components as children. The components communicate with the application by means of events. Depending on the current event the state is changed.
//Main app
<?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" xmlns:fld01="com.fld01.*">
<mx:ViewStack id="vsMain">
<s:NavigatorContent id="ncLogin">
<fld01:Login id="grLogin" evtLogin="{vsMain.selectedChild = ncNextPage}"/>
</s:NavigatorContent>
<s:NavigatorContent id="ncNextPage">
<fld01:Nextpage id="grNextPage" evtLogout="{vsMain.selectedChild = ncLogin}"/>
</s:NavigatorContent>
</mx:ViewStack>
</s:WindowedApplication>
//Login
<?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" width="400" height="300">
<fx:Metadata>
[Event(name="evtLogin", type="flash.events.Event")]
</fx:Metadata>
<fx:Script>
<![CDATA[
public function onLogin():void
{
this.dispatchEvent(new Event("evtLogin"));
}
]]>
</fx:Script>
<s:Button id="btn" x="40" y="50" label="Login" click="onLogin()"/>
</s:Group>
//NextPage
<?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"
width="400" height="300">
<fx:Metadata>
[Event(name="evtLogout", type="flash.events.Event")]
</fx:Metadata>
<fx:Script>
<![CDATA[
public function onLogout():void
{
this.dispatchEvent(new Event("evtLogout"));
}
]]>
</fx:Script>
<s:Label x="40" y="50" text="Login Success"/>
<s:Button id="btn" x="40" y="80" label="Logout" click="onLogout()"/>
</s:Group>
I try to create an editable datefield itemrenderer.
This itemrenderer works fine if I click on calendar button. But if I put data with keyboard, data isn't updating, if field is focus out data become empty.
See below my code
Datagrid column is like that
<mx:DataGridColumn dataField="echDate"
headerText="Date" headerStyleName="dgHeader"
itemEditor="ui.itemRenderer.irDateD" editorDataField="dateModif"/>
and item editor is
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<fx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.events.CalendarLayoutChangeEvent;
import mx.events.FlexEvent;
[Bindable] public var dateModif:String;
override public function set data(value:Object):void{
if(listData){
var newDate:Date;
var value1 = value.echDate;
if (value1 is String){
newDate = new DateUtility().dateStringToObject2(value1);
super.data = newDate;
dfDG.selectedDate = newDate;
dfDG.text = value1;
}
else if (value1 is Date){
super.data = value as Date;
dfDG.selectedDate = value1 as Date;
dfDG.text = new DateUtility().DateAsToString(value1);
}
}
}
protected function dfDG_changeHandler(event:CalendarLayoutChangeEvent):void
{
dateModif=dfDG.text;
}
]]>
</fx:Script>
<mx:DateField id="dfDG"
editable="true"
formatString="DD/MM/YYYY"
yearNavigationEnabled="true"
width="95"
change="dfDG_changeHandler(event)"
>
</mx:DateField>
</s:MXDataGridItemRenderer>
I'll happy if someone could help me to solve that
You can try this solution.
I have inserted the second DG to let you see, if data is updated or not.
I don't have your DateUtility().dateStringToObject2(value1), that's why I use a Validator instead.
The "backward connection" between Renderer and App is implemented by means of Binding.
When you use your DateUtility() to correct the input you can insert result to the text property of the DateField.
<?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" minWidth="955" minHeight="600">
<fx:Declarations>
<fx:Model id="cells">
<dataset>
<data>
<name>a</name>
<echDate>14/01/2013</echDate>
</data>
<data>
<name>b</name>
<echDate>15/01/2013</echDate>
</data>
</dataset>
</fx:Model>
</fx:Declarations>
<s:VGroup>
<mx:DataGrid
width="386" height="100" dataProvider="{cells.data}"
alternatingItemColors="[0xffffff]"
horizontalGridLineColor="0x999999"
horizontalGridLines="true"
verticalGridLineColor="0x999999"
sortableColumns="false"
resizableColumns="false" selectable="false">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name"/>
<mx:DataGridColumn dataField="echDate" headerText="Date"
itemRenderer="com.dgdatefield.irDateD"/>
</mx:columns>
</mx:DataGrid>
<mx:DataGrid
width="386" height="100"
dataProvider="{cells.data}">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name"/>
<mx:DataGridColumn dataField="echDate" headerText="Date"/>
</mx:columns>
</mx:DataGrid>
</s:VGroup>
</s:Application>
//Renderer
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<fx:Declarations>
<mx:DateValidator
id="dateValidator"
source="{dfDG}"
property="text"
inputFormat="DD/MM/YYYY"
wrongLengthError="The date format is not correct"
allowedFormatChars="/ - ."/>
</fx:Declarations>
<fx:Binding source="dfDG.text" destination="data.echDate"/>
<s:HGroup width="100%" horizontalAlign="center">
<mx:DateField
id="dfDG" text="{data.echDate}"
editable="true"
formatString="DD/MM/YYYY"
yearNavigationEnabled="true"
width="120"/>
</s:HGroup>
</s:MXDataGridItemRenderer>
I hope it can help you
I got very basic question. Why this is not working?!
<?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"
width="1000" height="550" minWidth="960" backgroundColor="#F2F0F0">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="test1" x="43" y="259" text="Label"/>
<fx:Script>
<![CDATA[
test1.text = "Yay! This works...!";
]]>
</fx:Script>
</s:Application>
I got this error: Access of undefined property.
Thanks!
You're setting the text before the component is created. Try putting the assignment into a method and calling the method on creationComplete:
<?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"
width="1000" height="550" minWidth="960" backgroundColor="#F2F0F0"
creationComplete="onCreationComplete()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="test1" x="43" y="259" text="Label"/>
<fx:Script>
<![CDATA[
public function onCreationComplete():void {
test1.text = "Yay! This works...!";
}
]]>
</fx:Script>
</s:Application>
How can HTML entities be made to work with TextFlow (specifically TEXT_LAYOUT_FORMAT)?
Example: ' is not converted into a single quote.
Any help would be appreciated.
Do you mean 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"
minWidth="955"
minHeight="600">
<fx:Script>
<![CDATA[
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.elements.TextFlow;
private const text:String = "< > " '";
]]>
</fx:Script>
<s:RichEditableText editable="false"
selectable="true"
textFlow="{TextConverter.importToFlow(text, TextConverter.TEXT_FIELD_HTML_FORMAT)}"
buttonMode="true"
width="100%"
height="100%" />
</s:Application>