I am trying bind an Object property value to a text field. (Well I have taken this as an example ... I have no.of form fields and to be bound by other values)
But when change its value on button click the text field is not getting updated?
Below is the example code,
<?xml version="1.0" encoding="utf-8"?>
<s:Application
minHeight="600"
minWidth="955"
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>
</fx:Declarations>
<fx:Script>
<![CDATA[
[Bindable]
var currentFormItem:Object = new Object();
public function changeName():void
{
currentFormItem.name = "hello";
}
]]>
</fx:Script>
<s:HGroup>
<s:TextInput id="test"
text="{currentFormItem.name}"/>
<s:Button click="changeName()"/>
</s:HGroup>
Thanks
I got the solution for this. I can just wrap this object in ObjectProxy.
Related
I used my app's resize handler to resize my component but it is throwing this error :
TypeError: Error #1009: Cannot access a property or method of a null object reference
Here is my code :
<?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"
resize="application2_resizeHandler(event)" >
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.events.ResizeEvent;
private var employeeName:String = 'ravi';
protected function application2_resizeHandler(event:ResizeEvent):void
{
mainGroup.width = stage.width - 10;
mainGroup.x = 5;
}
]]>
</fx:Script>
<s:Group width="100%" height="100%">
<s:VGroup id="mainGroup" >
<s:Label id="employeeNameLabel" text="{employeeName}" />
<s:Label id="departmentLabel" />
</s:VGroup>
<s:Button id="getData" />
</s:Group>
</s:Application>
You got the #1009 error because your resize event is fired before the creation of your objects. So, you should wait for that and that your app is added to the stage to be able to use the stage object.
For that, I think that the best event is the applicationComplete event, then you can add a resize event to resize your component ...
So you can do like this for example :
<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"
applicationComplete="application2_applicationCompleteHandler(event)" >
then
protected function application2_applicationCompleteHandler(event:FlexEvent):void
{
// if you want you can resize your component for the 1st time
// by calling the application2_resizeHandler() function
application2_resizeHandler(new ResizeEvent(ResizeEvent.RESIZE));
// add the resize event listener to your app
event.target.addEventListener(ResizeEvent.RESIZE, application2_resizeHandler);
}
Hope that can help.
I have an AdvancedDataGrid (whose dataProvider is a variable being bound from my main mxml file, not sure if this is relevant to my problem ). I'm setting one of the AdvancedDataGridColumn's editable property as true, and when I click on the cell in the UI, it is infact editable. But when I press enter/move to a different cell, the old value returns and the newly entered value is lost. Would anyone have any ideas why that's happening? Do I have to manually change the variable provided in the dataProvider?...I would think that would happen automatically right? I'd appreciate any help!
Thanks.
This traces out correct when I edit a field and press enter then click on the button to see trace output:
<?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" applicationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.HierarchicalData;
[Bindable]
private var companyHierarchy:HierarchicalData;
private var companyData:XML = <data>
<company name="Employees">
<department name="Unit 1">
<employee name="Dave" func="C# Developer"/>
<employee name="Bob" func="AS3 Developer"/>
<employee name="Clair" func="AS3 Architect"/>
</department>
<department name="Unit 2">
<employee name="John" func="ORACLE Developer"/>
<employee name="Sandra" func="HTML Developer"/>
</department>
</company>
</data>;
private function init():void
{
companyHierarchy = new HierarchicalData(companyData.company);
}
private function checkSetData():void
{
trace(companyData);
}
]]>
</fx:Script>
<mx:AdvancedDataGrid id="test" width="500" height="500" dataProvider="{companyHierarchy}"
displayItemsExpanded="true" editable="true" enabled="true">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="#name"
headerText="Companies"/>
<mx:AdvancedDataGridColumn dataField="#func"
headerText="Function"/>
</mx:columns>
</mx:AdvancedDataGrid>
<s:Button x="205" y="508" label="Button" click="checkSetData()"/>
</s:Application>
I am trying to access a variable defined in an mxml component from a TitleWindow but I cannot get it. I also declared a variable in my titleWindow which references to the component. And I also tried using parentDocument to access the variable but in vain.
Any precious help on this. Thanks.
See my codes below:
This is my component (Comp.xml) where I have declared the variable testVar.
<?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="100%" height="100%">
<fx:Script>
<![CDATA[
public var testVar:String = "Testing";
]]>
</fx:Script>
</s:Group>
This is my titleWindow code:
<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" left="10"
creationComplete="titlewindow1_initializeHandler(event)"
width="100%" height="100%"
>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import com.Comp;
public var varComp:Comp;
public function titlewindow1_initializeHandler(event:FlexEvent):void
{
//Alert.show(new String(Application));
Alert.show(new String(varComp.testVar));
}
]]>
</fx:Script>
</s:TitleWindow>
I have a mx Tab navigator and added several childs...I can use selectedindex(int) to open/select the respective (int) tab but How do I know the value of a selected/open tab???
Any Ideas.
Please help
You mean the navigator content?
<?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.core.INavigatorContent;
import mx.events.IndexChangedEvent;
protected function tabNavigator_changeHandler(event:IndexChangedEvent):void
{
var obj:INavigatorContent = tabNavigator.selectedChild;
}
]]>
</fx:Script>
<mx:TabNavigator id="tabNavigator"
change="tabNavigator_changeHandler(event)" />
</s:Application>
You need selectedIndex property (it is readable/writable). Also see Event.CHANGED to catch tab change.
I have an editable datagrid with a dataprovider which is basically Numbers. Is it possible to delete a value? When I do it it puts a 0 in that cell but I really need an empty value, like a Null or a NaN whose are going to be cleaned later with a labelFunction. BTW I also need the cells to keep the 0 if needed to. Thank you in advance.
Assign NaN to the value, and create a custom item renderer for your DataGrid:
<?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
{
if (isNaN(data[column.dataField]))
lblData.text = "";
else
lblData.text = Number(data[column.dataField]).toFixed(2);
}
]]>
</fx:Script>
<s:Label id="lblData"
top="9"
left="7" />
</s:GridItemRenderer>