Ive got a rather simple need to create a line chart. The data that I would like to chart is based on a single daily datapoint. xml example of data:
<?xml version="1.0"?>
<dataset>
<data>
<date>01/14/2013</date>
<number>80.6</number>
<indication>G</indication>
</data>
<data>
<date>01/15/2013</date>
<number>74.6</number>
<indication>A</indication>
</data>
<data>
<date>01/21/2013</date>
<number>79.4</number>
<indication>G</indication>
</data>
<data>
<date>01/22/2013</date>
<number>67.7</number>
<indication>A</indication>
</data>
</dataset>
The trick is that I want to alter the plotted line color based on the value in indication.
In other words if my first point is on 01/14/2013 I want the color of the line between that point and the next to be based on the indication so with the example data above it would be amber. Then from the second point to the 3rd green and from the thirs to the fourth amber again.
I really like the amstock charts but they seem to be lacking this functionality.
Has anyone seen any components capable of this or have ideas how I could do it with default flex 4.6 components?
I have an idea, i hope it will help you.
You can process your dataset and form a new one from it, so that each two points represent a single datasource for one line chart segment.
Then you go through all your segments and add them separate to the chart.
You need two classes to save informations about "points" and "parts"
//Part.as
public class Part
{
public var col:Number;
public var punkts:ArrayCollection;
}
//Punkt.as
public class Punkt
{
public var date:String;
public var number:Number;
public function Punkt(date:String, number:Number)
{
this.date = date;
this.number = number;
}
}
//here is your application
<?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"
creationComplete="init()">
<fx:Declarations>
<fx:Model id="myData">
<dataset>
<data>
<date>01/14/2013</date>
<number>80.6</number>
<indication>G</indication>
</data>
<data>
<date>01/15/2013</date>
<number>74.6</number>
<indication>A</indication>
</data>
<data>
<date>01/21/2013</date>
<number>79.4</number>
<indication>G</indication>
</data>
<data>
<date>01/22/2013</date>
<number>67.7</number>
<indication>G</indication>
</data>
<data>
<date>01/24/2013</date>
<number>47.7</number>
<indication>A</indication>
</data>
<data>
<date>01/25/2013</date>
<number>87.7</number>
<indication>G</indication>
</data>
</dataset>
</fx:Model>
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.Part;
import com.Punkt;
import mx.charts.series.LineSeries;
import mx.collections.ArrayCollection;
import mx.graphics.SolidColorStroke;
import mx.graphics.Stroke;
import mx.utils.ObjectProxy;
[Bindable]private var xAxis:ArrayCollection = new ArrayCollection();
[Bindable]private var dp:ArrayCollection = new ArrayCollection();
private function init():void
{
var prevCol:Number = 0x000000;
var len:int = myData.data.length;
var item:ObjectProxy;
var i:int;
for (i = 0; i < len; i++)
{
item = myData.data[i];
xAxis.addItem(item.date);
}
for (i = 0; i < len - 1; i++)
{
item = myData.data[i];
var part:Part = new Part();
switch (item.indication)
{
case "A":
part.col = 0xe48701;
break;
case "G":
part.col = 0xa5bc4e;
break;
}
part.punkts = new ArrayCollection();
part.punkts.addItem(new Punkt(item.date, item.number));
item = myData.data[i + 1];
part.punkts.addItem(new Punkt(item.date, item.number));
dp.addItem(part);
}
var mySeries:Array=new Array();
for each (var part:Part in dp)
{
var lineSeries:LineSeries = new LineSeries();
lineSeries.dataProvider = part.punkts;
lineSeries.xField = "date";
lineSeries.yField = "number";
lineSeries.setStyle('lineStroke', new SolidColorStroke(part.col, 3, 1));
mySeries.push(lineSeries);
}
lc.series = mySeries;
}
]]>
</fx:Script>
<mx:LineChart id="lc" x="184" y="55">
<mx:horizontalAxis>
<mx:CategoryAxis dataProvider="{xAxis}"/>
</mx:horizontalAxis>
</mx:LineChart>
</s:Application>
Related
I had a code like this
var str:string = "GeoCode: 3";
in this code I want ":" to be in bold.
How can I do that and this should be done in spark
Please help me
Thanks!
The simplest approach is to use TextFlowUtil.importFromString() and assign the resulting TextFlow object to a RichText component, like this:
<s:RichText id="textDisplay"/>
textDisplay.textFlow =
TextFlowUtil.importFromString('GeoCode<span fontWeight="bold">:</span> 3');
If you'd like to keep your original Strings intact, you can do a replace on them to add the span:
var str:String = "GeoCode: 3";
str = str.replace(/:/, '<span fontWeight="bold">:</span>');
textDisplay.textFlow = TextFlowUtil.importFromString(str);
I would do something like this:
The text property of the component is splitted into parts by means of ":" symbol. Then each part is added into a HGroup like a Label. Colons are added bold.
//Application
<?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" xmlns:com="com.*">
<s:VGroup left="20" top="20">
<com:GeoLabel text="GeoCode: 3"/>
<com:GeoLabel text="GeoCode: 5: Some Info: 123"/>
</s:VGroup>
</s:Application>
//GeoLabel component
<?xml version="1.0" encoding="utf-8"?>
<s:HGroup 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="120" height="25" gap="0">
<fx:Script>
<![CDATA[
import spark.components.Label;
private var _text:String;
public function get text():String
{
return _text;
}
public function set text(value:String):void
{
_text = value;
createMembers();
}
private function insertLabel(str:String, bold:Boolean):void
{
var la:Label = new Label();
la.text = str;
if (bold)
la.setStyle("fontWeight", "bold");
this.addElement(la);
}
private function createMembers():void
{
this.removeAllElements();
var arr:Array = text.split(":");
for (var i:int = 0; i < arr.length; i++)
{
if (i != 0)
insertLabel(":", true);
insertLabel(arr[i], false);
}
}
]]>
</fx:Script>
</s:HGroup>
After changing my OS's decimal separator as explained here:
( http://blogmines.com/blog/2010/03/11/how-to-change-the-decimal-separator-in-excel-2010/ ), I want to display a number in Flex that uses a comma for both the thousands separator and the decimal separator. Sounds simple enough, right?
I tried using three different NumberFormatters offered by Flex. Along the way, I learned that two of them didn't play well with others in the same class, even if using fully qualified class paths when declaring the variables, so I had to split them up into three classes, like so:
NF1 - spark.formatters.NumberFormatter
package dstrube
{
import flash.globalization.NumberParseResult;
import spark.formatters.NumberFormatter;
public class NF1
{
public static function get(value:String):String{
var nf1:NumberFormatter = new NumberFormatter();
var result:NumberParseResult = nf1.parse(value);
return nf1.format(result.value);
}
}
}
NF2 - flash.globalization.NumberFormatter
package dstrube
{
import flash.globalization.NumberParseResult;
import flash.globalization.NumberFormatter;
public class NF2
{
public static function get(value:String):String{
var nf2:NumberFormatter = new NumberFormatter("");// LocaleID.DEFAULT = same outcome as without
nf2.fractionalDigits = 2; //= same outcome as without
nf2.trailingZeros = true;
var result:NumberParseResult = nf2.parse(value);
//nf2.parseNumber(value); = NaN
return nf2.formatNumber(result.value)
}
}
}
NF3 - mx.formatters.NumberFormatter (deprecated)
package dstrube
{
//import mx.formatters.NumberBaseRoundType;
import mx.formatters.NumberFormatter;
public class NF3
{
public static function get(value:String):String{
var nf3:NumberFormatter = new NumberFormatter();
//nf3.rounding = NumberBaseRoundType.NEAREST; //no effect in this case
return nf3.format(value);
}
}
}
and finally, the main
<?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"
creationComplete="init()"
>
<fx:Script>
<![CDATA[
import dstrube.NF1;
import dstrube.NF2;
import dstrube.NF3;
[Bindable]
public var s:String = "";
protected function init():void{
var value:String = "5558049.90360013";
s = "spark.formatters.NumberFormatter = " + NF1.get(value); //5,558,049.90
s += "\n flash.globalization.NumberFormatter = " + NF2.get(value);//5,558,049,00
s += "\n mx.formatters.NumberFormatter = " + NF3.get(value); //5,558,049.90360013
}
]]>
</fx:Script>
<s:TextArea id="textArea" text="{s}" width="100%" height="100%" />
</s:Application>
The smartest of the three NumberFormatters is flash.globalization.NumberFormatter for recognizing decimal separator, but it rounds incorrectly, showing 5,558,049,00 instead of 5,558,049,90
Any ideas?
You can either:
Explicitly setting the formatter's properties will give you the
output you require.
Set the formatter to use the default locale.
[Bindable] protected var formatted:String;
protected function init(event:FlexEvent):void
{
var formatter:NumberFormatter = new NumberFormatter();
// Option 1 set explicitly
formatter.decimalSeparator = ",";
formatter.fractionalDigits = 2;
formatter.trailingZeros = true;
// Option 2 set default locale to be the locale
formatter.setStyle("locale", LocaleID.DEFAULT);
formatted = formatter.format("5558049.90360013");
}
]]>
</fx:Script>
<s:Label text="{formatted}" />
The output is "5,558,049,90".
This way will display whatever the decimal separator is set to be in the OS's settings.
<?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"
initialize="init(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import spark.formatters.NumberFormatter;
import flash.globalization.NumberFormatter;
[Bindable] protected var formatted:String;
protected function init(event:FlexEvent):void
{
var formatter:spark.formatters.NumberFormatter = new spark.formatters.NumberFormatter();
var nf2:flash.globalization.NumberFormatter = new flash.globalization.NumberFormatter("");
formatter.decimalSeparator = nf2.decimalSeparator;
formatter.fractionalDigits = 2;
formatter.trailingZeros = true;
formatted = formatter.format("5558049.90360013");
}
]]>
</fx:Script>
<s:Label text="{formatted}" />
</s:Application>
I want to make an App using SplitViewNavigator container which contains List of cities in left view and Detail about the city in right view, In right view there is a text input through I get Name of city and store in a SQLite Database, and that name should be added to list in left view from SQLite Database I got started with flowing code in Main.mxml:
<?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"
applicationDPI="160"
initialize="application1_initializeHandler(event)">
<fx:Script>
<![CDATA[
import model.DataModel;
import mx.events.FlexEvent;
import valueobject.CityValueObject;
import utillities.CityUtils;
public var sqlConnection:SQLConnection;
protected var statement:SQLStatement;
protected function application1_initializeHandler(event:FlexEvent):void
{
sqlConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirectory.resolvePath("cityDB.db"), SQLMode.CREATE);
statement.sqlConnection = sqlConnection; // Here error occurs saying that Error #1009: Cannot access a property or method of a null object reference.
statement.text = "CREATE TABLE IF NOT EXISTS CITYNAME (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"nameofcity TEXT)";
statement.execute();
DataModel.getInstance().connection = sqlConnection;
CityUtils.getAllCities();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SplitViewNavigator id="svn" width="100%" height="100%">
<s:ViewNavigator width="30%" height="100%" id="list_of_cities" firstView="views.ListOfCities"/>
<s:ViewNavigator width="70%" height="100%" id="display_contents" firstView="views.DisplayContents"/>
</s:SplitViewNavigator>
My model.DataModel is an action script class:
package model
{
import flash.data.SQLConnection;
import mx.collections.ArrayCollection;
[Bindable]
public class DataModel
{
public var connection:SQLConnection;
public var cityList:ArrayCollection = new ArrayCollection();
public var logs:String="Application Logs........\n";
public static var _instance:DataModel;
public function DataModel()
{
}
public static function getInstance():DataModel
{
if(_instance == null)
{
_instance = new DataModel();
}
return _instance;
}
}
}
My valueobject.CityValueObject class is:
package valueobject
{
[Bindable]
public class CityValueObject
{
public var id:uint;
public var nameofcity:String;
}}
And My uttillities.CityUtils class is ::
package utillities
{
import flash.data.SQLResult;
import flash.data.SQLStatement;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import model.DataModel;
import mx.collections.Sort;
import mx.collections.SortField;
import valueobject.CityValueObject;
public class CityUtils
{
public static function getAllCities():void
{
var contactListStatement:SQLStatement = new SQLStatement();
contactListStatement.sqlConnection = DataModel.getInstance().connection;
contactListStatement.text = "SELECT * FROM CITYNAME";
contactListStatement.execute();
var result:SQLResult = contactListStatement.getResult();
if( result.data!=null)
{
DataModel.getInstance().cityList.removeAll();
for(var count:uint=0;count<result.data.length;count++)
{
var cityVO:CityValueObject = new CityValueObject();
cityVO.id = result.data[count].id;
cityVO.nameofcity = result.data[count].city;
DataModel.getInstance().cityList.addItem(cityVO);
}
}
sortData();
}
public static function sortData():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "cityName";
dataSortField.numeric = false;
/* Create the Sort object and add the SortField object created earlier to the array of fields to sort on. */
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
/* Set the ArrayCollection object's sort property to our custom sort, and refresh the ArrayCollection. */
DataModel.getInstance().cityList.sort = numericDataSort;
DataModel.getInstance().cityList.refresh();
}
public static function updateLog(newLog:String):void
{
DataModel.getInstance().logs += new Date().time+" :-> "+newLog+"\n";
}
}
}
My left containing list of cities is :
<?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="Cities"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import model.DataModel;
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
import mx.events.IndexChangedEvent;
import spark.components.SplitViewNavigator;
import spark.components.ViewNavigator;
import spark.transitions.ViewTransitionBase;
protected function myList_changeHandler():void {
// Create a reference to the SplitViewNavigator.
var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
// Create a reference to the ViewNavigator for the Detail frame.
var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(1) as ViewNavigator;
detailNavigator.transitionsEnabled = false;
// Change the view of the Detail frame based on the selected List item.
detailNavigator.pushView(DisplayContents, list_of_cities.selectedItem);
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%">
<s:List id="list_of_cities" height="100%" width="100%" change="myList_changeHandler();"
dataProvider="{DataModel.getInstance().cityList}" labelField="nameofcity">
</s:List>
</s:VGroup>
and in last my Display Detail about city is simply like this :
<?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="Detail About City"
>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:actionContent>
<s:CalloutButton id="add_call_out_button" label="Add City" verticalPosition="after"
icon="#Embed('assets/add.png')" calloutDestructionPolicy="never">
<!-- layout the callout content here -->
<s:calloutLayout>
<s:VerticalLayout paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" horizontalAlign="center" gap="5"/>
</s:calloutLayout>
<s:calloutContent>
<s:TextInput id="city_name_input" prompt="Enter City Name" text="Sydney"/>
<s:HGroup gap="40">
<s:Button id="add_city_name" label="Add City" width="150" height="40" click="add_city_name_clickHandler()"/>
<s:CheckBox id="preferred_cbox" label="Preferred" height="40" />
</s:HGroup>
</s:calloutContent>
</s:CalloutButton>
<s:Button id="remove_city_name" label="Remove" width="120" height="40"
click="remove_city_name_clickHandler()" icon="#Embed('assets/delete.png')"/>
</s:actionContent>
<s:Label id="nameSomeThing" text="{data.Description}"/>
<fx:Script>
<![CDATA[
import model.DataModel;
import spark.components.SplitViewNavigator;
import spark.components.ViewNavigator;
protected function add_city_name_clickHandler():void
{
var sqlStatement:SQLStatement = new SQLStatement();
sqlStatement.sqlConnection = DataModel.getInstance().connection;
sqlStatement.text = "INSERT INTO CITYNAME (nameofcity)" +
"VALUES(:nameofcity)";
sqlStatement.parameters[":nameofcity"] = city_name_input.text;
sqlStatement.execute();
var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
// Create a reference to the ViewNavigator for the Detail frame.
var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(1) as ViewNavigator;
detailNavigator.transitionsEnabled = false;
// Change the view of the Detail frame based on the selected List item.
detailNavigator.popToFirstView();
}
protected function remove_city_name_clickHandler():void
{
// TODO Auto-generated method stub
}
]]>
</fx:Script>
the above view(Display Detail) is still in development but at this stage I was Trying to add City Name to list of cities by getting name from city name input text input but at:
statement.sqlConnection = sqlConnection; // Here error occurs saying that Error #1009: Cannot access a property or method of a null object reference.
Iget that error and not be able to go ahead.
Can any one please give me the way to solve my this problem by my code givien above or suggest me an other way to meet my needs by this App Thanks in Advance...
As the error message says, statement is null.
I don't see any code that would initialize it.
You need:
statement = new SQLStament();
(And I don't see any reason why this variable would need to be outside the application1_initializeHandler function.)
I am trying to bind data within a ArrayList to a list, but here only the last element shows up on the list(99), not the entire contents of the arraylist.
private function completeHandler(event:Event):void
{
var xmlData:XML = XML(event.target.data);
trace(xmlData);
var i:int = 0;
for (i;i<100;i++)
{
var arr:ArrayList = new ArrayList();
arr.addItem(i);
trace(arr);
}
list.dataProvider = arr;
}
I am not able to figure out what to do here?
You're creating an ArrayList with one item a 100 times. Replace with this and you should be fine:
var arr:ArrayList = new ArrayList();
for (var i:int = 0; i<100; i++) {
arr.addItem(i);
}
Or better yet, just wrap your XML in an XMLListCollection instead of copying the nodes one by one (assuming it is the actual content of the XML data you want instead of the indices):
private function completeHandler(event:Event):void
{
var xmlData:XML = XML(event.target.data);
list.dataProvider = new XMLListCollection(xmlData.children());
}
(Note that this is not DataBinding: it is just setting the dataProvider property)
check this code this will help you,
you can navigate through all data on the basis of rowcount of list....
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var _index:int = 0;
private var _coll:ArrayCollection = new ArrayCollection([{name:'ashish',age:'28'},{name:'abhi',age:'29'},{name:'kunal',age:'27'},
{name:'ashish1',age:'28'},{name:'abhi1',age:'29'},{name:'kunal1',age:'27'},
{name:'ashish2',age:'28'},{name:'abhi2',age:'29'},{name:'kunal2',age:'27'},
{name:'ashish3',age:'28'},{name:'abhi3',age:'29'},{name:'kunal3',age:'27'}]);
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
if((_index-li.rowCount>=0))
_index = _index - li.rowCount;
}
protected function button2_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
if((_index+li.rowCount<_coll.length))
_index = _index + li.rowCount;
}
]]>
</mx:Script>
<mx:List id="li" dataProvider="{_coll.source.slice(_index,(_index+li.rowCount))}" labelField="name" rowCount="3" width="100"/>
<mx:HBox>
<mx:Button label="<-" click="button1_clickHandler(event)"/>
<mx:Button label="->" click="button2_clickHandler(event)"/>
</mx:HBox>
</mx:Application>
I'm facing a strange issue with flex and validator.
Here is the code:
TestMain.xml
<?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">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.validators.StringValidator;
import utils.ValidableProperty;
[Bindable] public var nameID:ValidableProperty;
public function start():void {
var nameIDValidator:StringValidator = new StringValidator();
nameIDValidator.required = true;
nameIDValidator.maxLength = 35;
nameID = new ValidableProperty(nameIDValidator);
nameID.validate();
}
]]>
</fx:Script>
<s:applicationComplete>
start();
</s:applicationComplete>
<s:minHeight>600</s:minHeight>
<s:minWidth>955</s:minWidth>
<mx:Form color="0x323232" paddingTop="0">
<s:Label text="See strange behavior of errorString during validator operation with validate."/>
<mx:FormItem label="Name">
<mx:TextInput id="nameInput" width="300" errorString="#{nameID.errorMessage}" text="#{nameID.value}"/>
</mx:FormItem>
</mx:Form>
ValidableProperty.as
package utils
{
import flash.events.EventDispatcher;
import mx.events.PropertyChangeEvent;
import mx.events.ValidationResultEvent;
import mx.validators.Validator;
public class ValidableProperty extends EventDispatcher
{
[Bindable]
public var value:Object;
private var validator:Validator;
[Bindable]
public var isValid:Boolean;
[Bindable]
public var errorMessage:String;
private var statusChangeHandler:Function;
public function ValidableProperty(validator:Validator, statusChangeHandler:Function=null,
target:IEventDispatcher=null) {
super(target);
this.validator = validator;
this.statusChangeHandler = statusChangeHandler;
this.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, propertyChangeHandler);
}
private function propertyChangeHandler(evt:PropertyChangeEvent):void {
if (evt.property == "value") {
this.validate();
}
}
public function validate():void {
var result:ValidationResultEvent = this.validator.validate(this.value);
this.isValid = (result.type == ValidationResultEvent.VALID);
if (isValid) {
this.errorMessage = null;
}
else {
this.errorMessage = result.message;
}
if (statusChangeHandler != null)
statusChangeHandler();
}
public function set required(required:Boolean):void {
if (validator == null)
return;
validator.required = required;
}
}
}
When you execute this simple code, when writing a value, for example "A", the errorMessage value "this field is required" will disappear but the red color on the inputtext border will still be there with the blue color.
When deleting the A value, this time the blue color will be there with the red one (cannot reproduce all the time) and the error message "this field is required".
What am I missing here? Is it a bug in flex? We cannot have both of red and blue colors on the textinput border.
I am using Eclipse with Flex SDK 4.5.0 (build 20967)
This is not a bug in Flex. This is a bug with how you're coding it all. If you were to follow the example in the documentation, it would work.
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate StringValidator. -->
<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">
<fx:Declarations>
<mx:StringValidator source="{nameInput}" property="text"
tooShortError="This string is shorter than the minimum length of 4. "
tooLongError="This string is longer than the maximum allowed length of 35."
minLength="4" maxLength="35"/>
</fx:Declarations>
<s:Form>
<s:FormItem label="Name">
<s:TextInput id="nameInput" width="300" text="{nameID.value}"/>
</s:FormItem>
</s:Form>
</s:Application>
I finally resolve this. I was using mx:TextInput instead of s:TextInput. Thanks J_A_X for your suggestion !