spark Text area height adjust to content - apache-flex

i want to adjust the size of my text area in action script based on the text i put inside dynamically, but absolutly don't know how to do that... searched a lot for nothing. Here is my code if it can help you situate the problem. I want to adjust the height of msgLabel to the content.
Thanks a lot ;).
public function createTweet(tweet:XML, lineName:String, isTweetInList:Boolean):IVisualElement{
var authorS:String = tweet.posterName;
var tweetID:String = tweet.tweetID;
//Main vertical group
var vg:VGroup = new VGroup();
vg.percentWidth = 100;
if(!isTweetInList){
//Add the new VGroup to the tweetTabHolder
tweetTabHolder[tweetID+lineName] = vg;
//Add the new tweetID to the tweet posted by an author
if(tweetByLineByAuthor[authorS] == null)
tweetByLineByAuthor[authorS] = new Dictionary();
if(tweetByLineByAuthor[authorS][lineName] == null)
tweetByLineByAuthor[authorS][lineName] = new ArrayList();
tweetByLineByAuthor[authorS][lineName].addItem(tweetID);
}
vg.setStyle("backgroundAlpha", 0);
vg.paddingLeft = 20;
var sp0:Spacer = new Spacer();
sp0.height = 10;
vg.addElement(sp0);
//Tweet Content
//Author
var hgA:HGroup = new HGroup();
var aSpacer:Spacer = new Spacer();
aSpacer.width = 10;
hgA.addElement(aSpacer);
var authorLabel:RichText = new RichText();
authorLabel.text = authorS;
authorLabel.setStyle("fontSize",20);
authorLabel.setStyle("fontWeight",FontWeight.BOLD);
authorLabel.setStyle("color",authorColor);
authorLabel.addEventListener("click",authorClickHandler);
authorLabel.addEventListener(MouseEvent.MOUSE_OVER,authorFocusInHandler);
authorLabel.addEventListener(MouseEvent.MOUSE_OUT,authorFocusOutHandler);
hgA.addElement(authorLabel);
if(tweet.posterName == userNameLogged || isTweetInList){
var abs1:Spacer = new Spacer();
abs1.width = 25;
hgA.addElement(abs1);
hgA.addElement(createDeleteTweetButton(tweetID,vg, isTweetInList));
var abs2:Spacer = new Spacer();
}
if(!isTweetInList){
abs2.width = 4;
hgA.addElement(abs2);
hgA.addElement(createFavorisButton(tweetID));
}
vg.addElement(hgA);
//Msg
var hgM:HGroup = new HGroup();
var mSpacer:Spacer = new Spacer();
mSpacer.width = 15;
hgM.addElement(mSpacer);
var msgLabel:TextArea = new TextArea();
hgM.addElement(msgLabel);
hgM.percentWidth = 100;
msgLabel.percentWidth = 100;
msgLabel.text = tweet.msg;
msgLabel.setStyle("fontSize",12);
msgLabel.setStyle("color",msgColor);
msgLabel.editable = false;
msgLabel.setStyle("lineBreak", "toFit");
vg.addElement(hgM);
//Date
var hgD:HGroup = new HGroup();
var dSpacer:Spacer = new Spacer();
dSpacer.width = 10;
hgD.addElement(dSpacer);
var dateLabel:Label = new Label();
dateLabel.text = tweet.postingDate.date;
dateLabel.setStyle("fontSize",10);
dateLabel.setStyle("color",dateColor);
hgD.addElement(dateLabel);
vg.addElement(hgD);
var sp1:Spacer = new Spacer();
sp1.height = 10;
vg.addElement(sp1);
var hr:HRule = new HRule();
hr.percentWidth = 90;
hr.x = 20;
vg.addElement(hr);
return vg;
}

First off, why are you using Actionscript when your application is clearly Flex? You could reduce that mess of code by 2/3. Also, last I checked they all resize to their content unless you specify their dimensions. Either way, here's an example which works great:
<?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[
[Bindable] private var someText:String = "Enter long text here.";
]]>
</fx:Script>
<s:RichEditableText selectable="true" editable="false" text="{someText}" multiline="true" width="100%" />
</s:Application>

Related

Finding previous word boundary with enter key?

This code works great and it get the last word, but when I use enter key
it behaves erroneously and stops getting last word(s). When I comment the findPreviousWordBoundary line, it gets all text:
<fx:Script>
<![CDATA[
import flashx.textLayout.elements.ParagraphElement;
protected function togglebutton1_clickHandler(event:MouseEvent):void {
var urlLoader:URLLoader = new URLLoader();
var suggestions:Array = new Array();
var suggested:Array = new Array();
var textfields:Array = new Array();
var format:TextFormat = new TextFormat();
var currentSelection:int = -1;
mytextflow.addEventListener(KeyboardEvent.KEY_UP, suggest);
function suggest(event:KeyboardEvent):void {
suggested = [];
var activePos:int = mytextflow.selectionActivePosition
var curParagraph:ParagraphElement =
mytextflow.textFlow.findLeaf(activePos).getParagraph();
var wordBoundary:int = curParagraph.
findPreviousWordBoundary(activePos);
//var lastword:String = curParagraph.getText(wordBoundary,activePos);
}
}
]]>
</fx:Script>
<s:ToggleButton x="21" y="10"
click="togglebutton1_clickHandler(event)"/>
<s:RichEditableText
id="mytextflow"
x="111"
y="43"
width="363"
height="285"
backgroundColor="#C39191"/>
</s:Application>

How to create an ArrayCollection of Objects?

I new to flex, I have a class shown below:
public class Items extends Object
{
public function Items(){
super();
}
public var name:String;
public var count:int;
}
How do I create an ArrayCollection of type Items?
Thanks.
var item1:Items = new Items();
item1.name = "Name1";
item1.count = 5;
var item2:Items = new Items();
item2.name = "Name2";
item2.count = 7;
var items:ArrayCollection = new ArrayCollection([item1, item2]);
Another way:
var items:ArrayCollection = new ArrayCollection();
var item1:Items = new Items();
item1.name = "Name1";
item1.count = 5;
items.addItem(item1);
var item2:Items = new Items();
item2.name = "Name2";
item2.count = 7;
items.addItem(item2);
You can also create these in mxml (inside if you're using flex 4)
<s:ArrayCollection id="theCollection">
<namespace:Items name="name 1" count="5" />
<namespace:Items name="name 2" count="6" />
<namespace:Items name="name 3" count="7" />
<namespace:Items name="name 4" count="8" />
</s:ArrayCollection>
Then reference the array by its id.
Somewhere in your code:
var ac : ArrayCollection = new ArrayCollection();
var newItem : Items = new Items();
newItem.name = 'some value';
newItem.count = 1;
ac.addItem(newItem);
newItem = new Items();
newItem.name = 'some other value';
newItem.count = 2;
ac.addItem(newItem);
newItem = new Items();
newItem.name = 'Yet another value';
newItem.count = 3;
ac.addItem(newItem);
...
It may be worth nothing that ArrayCollections are not typed in the same way that a Vector may be, so there is nothing you can do to force all items in your collection to be of the Items type. [Unless you extend ArrayCollection somehow and override the addItem / addItemAt methods to throw errors if the type is wrong.

moving between states I get an error in Flex

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
so i have a function that runs in state1 and has a
while(myCanvas.rawChildren.numChildren > 0){
myCanvas.rawChildren.removeChildAt(0);
}
//this code is definitely the problem....
I can move to state2, but when I move back to state1 i get the error.
why? the function that has the while loop only runs when something is searched in state1, so why is it running when coming back from state2?
edit...
so i did i test for a function that runs at app initialization:
private function init():void{
trace(g);
if(g == true){
while(myCanvas.rawChildren.numChildren > 0){
myCanvas.rawChildren.removeChildAt(0);
}
g = false;
}
trace(g);
}
It shouldnt run one it comes back to state1, but i still get the error. So basically as long as that while loop runs once while in state1 I can never get back to state1
<mx:states>
<mx:State name="contactform">
<mx:AddChild position="lastChild">
<mx:Canvas id="msgCanvas" backgroundColor="0xEEEEEE" height="121" y="158" width="800" fontWeight="normal" fontSize="12" backgroundAlpha="0.02" x="0">
</mx:Canvas>
</mx:AddChild>
<mx:AddChild position="lastChild">
<custom:email_cmp x="150" y="287" height="213"/>
</mx:AddChild>
</mx:State>
<mx:State name="main">
<mx:AddChild position="lastChild">
<mx:Canvas id="myCanvas" backgroundColor="0xEEEEEE" height="342" y="158" width="800" fontWeight="normal" fontSize="12" backgroundAlpha="0.02" x="0">
</mx:Canvas>
</mx:AddChild>
</mx:State>
</mx:states>
public function mainFunction():void{
origArray = [];
var cache:int = 0;
if(myCanvas.rawChildren.numChildren > 0){
myCanvas.rawChildren.removeChildAt(0);
}
//text format for links
var hFormat:TextFormat = new TextFormat();
hFormat.font = "Verdana";
hFormat.color = 0x000000;
hFormat.size = 15;
//text format end
var sprite1:Sprite = new Sprite();
var textQ:TextField = new TextField();
textQ.mouseEnabled = false;
if(amt_cnt.count == 1){
amt_cnt.end = amt_cnt.endCache;
amt_cnt.start = amt_cnt.startCache;
//set the text
textQ.defaultTextFormat = hFormat;
textQ.text = "Still can't find your answer? Need more help?";
textQ.x = 270;
textQ.y = 300;
textQ.width = textQ.textWidth +20;
textQ.selectable = false;
sprite1.addChild(textQ);
sprite1.buttonMode = true;
myCanvas.rawChildren.addChild(sprite1);
sprite1.addEventListener(MouseEvent.CLICK, moreHelp);
}else{
amt_cnt.end = amt_cnt.endCache;
amt_cnt.start = amt_cnt.startCache;
textQ.defaultTextFormat = hFormat;
textQ.text = "More Questions...";
textQ.x = 275;
textQ.y = 300;
textQ.width = textQ.textWidth +20;
textQ.selectable = false;
sprite1.addChild(textQ);
sprite1.buttonMode = true;
myCanvas.rawChildren.addChild(sprite1);
sprite1.addEventListener(MouseEvent.CLICK, moreQuestions);
}
var fontSize:int = 12;
//text formatting for the displayed question list Begin
var qFormat:TextFormat = new TextFormat();
qFormat.font = "Verdana";
qFormat.color = 0x000000;
qFormat.size = fontSize;
//ending text format
for(var t:uint = amt_cnt.start; t<amt_cnt.end; t++){
/*if(t == 0){
var topQ:TextField = new TextField();
topQ.text = full_array[t][1];
mainQsprite.addChild(topQ);
}*/
var qSprite:Sprite = new Sprite();
var txt:TextField = new TextField();
txt.defaultTextFormat = qFormat;
txt.text = full_array[t][0];
txt.selectable = false;
txt.mouseEnabled = false;
txt.border = false;
txt.width = 500; // how wide you want the text to go.
var numLines:Number = Math.floor(txt.textWidth/txt.width)+1; //calculates number of lines of the textfield.
txt.height = ((fontSize+8)*numLines);
txt.wordWrap = true;
qSprite.x = 30;
qSprite.y = 350;
qSprite.alpha = 0;
var temp_a:Number = cache; //20 is the padding between questions displayed
if(t != amt_cnt.end-1){
Tweener.addTween(qSprite, {y:temp_a, alpha:1, time:1, delay:t*0.1, transition:"easeoutexpo"}); //tweener INNNNN!
}else{
Tweener.addTween(qSprite, {y:temp_a, alpha:1, time:1, delay:t*0.1, transition:"easeoutexpo", onComplete:runTop}); //tweener INNNNN!
}
cache = txt.height + temp_a;
qSprite.buttonMode = true;
origArray[t] = new Array(qSprite.x,temp_a, qSprite);
mainDict[qSprite] = new Object();
mainDict[qSprite].question = full_array[t][0];
mainDict[qSprite].answer = full_array[t][1];
mainDict[qSprite].count = full_array[t][2];
mainDict[qSprite].top = full_array[t][3];
mainDict[qSprite].origX = qSprite.x;
mainDict[qSprite].origY = temp_a;
mainDict[qSprite].id = t;
mainDict[qSprite].height = txt.height;
amt_cnt[t] = new Object();
amt_cnt[t].hit = false;
qSprite.addChild(txt);
qSprite.addEventListener(MouseEvent.CLICK, clicked);
qSprite.addEventListener(MouseEvent.MOUSE_OVER, over);
qSprite.addEventListener(MouseEvent.MOUSE_OUT, out);
myCanvas.rawChildren.addChild(qSprite);
if(full_array[t][3] == true){
var thereIsTop:Boolean = true;
}
}
amt_cnt.array = origArray;
/*if(thereIsTop == true){
topAnswer(); //makes the top answer open first
thereIsTop = false;
}*/
}
So this the mainfunction. The top part has the states. main state is loaded first and has the myCanvas canvas. Everything in mainfunction adds to myCanvas.
This is my first time working with flex, so tell me if there is a better way of doing this.Thanks?
I really need to get this solved. I've been stressing over this for weeks.
I understand why you might not use mx:RemoveChild in your state (if you're managing your states in the easier-to-love mxml states property), but it looks like your code is trying to do what removeAllChildren() already does. Can you use removeAllChildren instead? Though, it would be nice to have more code to see what you're trying to accomplish.
Maybe you're handling an enterState event with this code ?

Disabling radiobuttongroup

Since Repeater component won't generate radiobuttongroup in mxml, and since I can't do the same through ActionScript because radiobuttongroup doesn't have an id property when I try to create it that way, is there a way to disable radiobuttons at all? As far as I can see, the only thing I can set and access is groupName property of radiobuttons.
For Repeater component I tried using xml directly
<mx:XML id="xquiz" source="quiz.xml" />
with this code:
<mx:Repeater dataProvider="{xquiz.question}" id="rep">
<mx:Label text="{rep.currentItem.content}" />
<mx:Repeater dataProvider="{rep.currentItem.answer}" id="rep2">
<mx:RadioButton label="{rep2.currentItem}" groupName="{'rbg'+rep.currentIndex}" click="checkAnswers(event)" value="{rep2.currentItem.#correct}" />
</mx:Repeater>
</mx:Repeater>
and cannot use repeater to generate radiobuttongroup since it's not a visible component.
I also tried ActionScript approach but with HTTPService mxml component to fetch xml file.
<mx:HTTPService id="srv" url="quiz.xml" resultFormat="e4x" result="handleResult(event);" fault="handleFault(event);"/>
and here's actionscript snippet:
private var xQuizData:XML
private function handleResult(event:ResultEvent):void {
xQuizData = event.result as XML;
initApp();
}
private function initApp():void {
var cnt:Number = 0;
for each (var question:XML in xQuizData.*) {
var lbl:Label = new Label();
lbl.text = question.content;
panel.addChild(lbl);
lbl.visible = true;
var cnt2:Number = 0;
for each (var answer:XML in question.answer) {
var rb:RadioButton = new RadioButton();
rb.id=String(cnt);
rb.label=answer;
rb.groupName="rbg"+String(cnt);
if (answer.hasOwnProperty("correct")) {
rb.value=true;
}
panel.addChild(rb);
rb.visible = true;
cnt2++;
}
cnt++;
}
}
I want to be able to catch clicks from radiobuttongroup controls, but can't get them to generate at all if with repeater or can't assign them id if with actionscript.
XML contents would look something like this:
<quiz>
<question>
<content>Some question?</content>
<answer>Answer one</answer>
<answer correct="true">Answer two</answer>
<answer>Answer three</answer>
<answer>Answer four</answer>
</question>
</quiz>
I'm having a hard time following what you are trying to do from your snippets, so here's a snippet of mine that should do exactly what your wanting. Hopefully you can review it and adapt it for your problem.
public function buildVBox():void{
tempVBox.removeAllChildren();
var iterator:Number = 0;
for each (var i:XML in myXML.children()){
var tempCanv:Canvas = new Canvas();
tempCanv.id = iterator.toString();
var tempRadYes:RadioButton = new RadioButton;
tempRadYes.x = 30;
tempRadYes.y = 20;
tempRadYes.origY = 20;
tempRadYes.groupName = "rbg" + iterator.toString();
tempRadYes.value = 1;
tempRadYes.label = "Yes"
tempCanv.addChild(tempRadYes);
var tempRadNo:extRadioButton = new extRadioButton;
tempRadNo.x = 80;
tempRadNo.y = 20;
tempRadNo.origY = 20;
tempRadNo.groupName = "rbg" + iterator.toString();
tempRadNo.value = 2;
tempRadNo.label = "No"
tempCanv.addChild(tempRadNo);
var tempRadNA:extRadioButton = new extRadioButton;
tempRadNA.x = 120;
tempRadNA.y = 20;
tempRadNA.origY = 20;
tempRadNA.groupName = "rbg" + iterator.toString();
tempRadNA.value = 0; tempRadNA.label = "N/A"
tempCanv.addChild(tempRadNA);
tempVBox.addChild(tempCanv);
iterator++;
}
}
Got a solution from here: http://www.jonathanrowny.com/journal/radiobuttongroup-inside-repeater

How to generate a form(<mx:form>) dynamically in flex?

I need to generate a mx:form from an xml file that I am getting from httpservice.
Also I need to prefill the data that I am getting from the form itself.
Can someone give me a sample code?
You would have to expand on this obviously, but this is how I would go about building a dynamic form..
import mx.controls.TextInput;
import mx.containers.FormItem;
import mx.containers.Form;
private var fxml:XML =
<form>
<fields>
<field type="text" label="name" default="gary"/>
<field type="text" label="surname" default="benade"/>
</fields>
</form>
private function init():void
{
var form:Form = new Form();
form.setStyle("backgroundColor", 0xFFFFFF);
for each( var xml:XML in fxml..field)
{
switch( xml.#type.toString())
{
case "text":
var fi:FormItem = new FormItem();
fi.label = xml.#label;
var ti:TextInput = new TextInput();
ti.text = xml.#default.toString();
fi.addChild( ti);
form.addChild( fi);
break;
case "int":
break;
}
}
this.addChild( form);
}
Check this out: MXMLLoader for Flex 3. HTH.
<?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"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="handleCreationComplete()">
<fx:Declarations>
<fx:XML id="formdata">
<userinfoform>
<user>
<firstname inputtype="TextInput" formlabel="First Name" required="true">true</firstname>
<lastname inputtype="TextInput" formlabel="Last Name" required="true">true</lastname>
<Middlename inputtype="TextInput" formlabel="Middle Name" required="false">true</Middlename>
<nickname inputtype="TextInput" formlabel="Nick Name" required="false">false</nickname>
<combobox inputtype="ComboBox" formlabel="Gender" required="true">Male,Female</combobox>
<type inputtype="ComboBox" formlabel="Type" required="false">Book,Cds,Games</type>
<radioButtonGroup inputtype="RadioButtonGroup" formlabel="Gender" required="false">
<radiobutton inputtype="RadioButton" formlabel="Gender" required="true">Male</radiobutton>
<radiobutton inputtype="RadioButton" formlabel="Gender" required="true">Female</radiobutton>
</radioButtonGroup>
</user>
</userinfoform>
</fx:XML>
</fx:Declarations>
`enter code here`<fx:Script>
<![CDATA[
import flashx.textLayout.events.SelectionEvent;
import mx.collections.ArrayCollection;
import mx.core.UIComponent;
import mx.events.ItemClickEvent;
import mx.events.ValidationResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.validators.NumberValidator;
import mx.validators.StringValidator;
import spark.components.ComboBox;
import spark.components.DropDownList;
import spark.components.RadioButton;
import spark.components.RadioButtonGroup;
import spark.components.TextArea;
import spark.components.Form;
import spark.components.FormItem;
import spark.components.TextInput;
import spark.components.RadioButtonGroup;
import spark.components.RadioButton;
private function handleCreationComplete():void
{
//Below line can be used for XML from an external source
//XMLService.send();
buildForm(new XML(formdata));
}
private function errorHandler(evt:FaultEvent):void
{
//Alert.show("Error: " + evt.fault.message);
}
private function resultHandler(evt:ResultEvent):void
{
buildForm(new XML(evt.result));
}
private function buildForm(xml:XML):void
{
var lst:XMLList = xml.children();
for(var i:int = 0; i < lst.length(); i++)
{
var x:XMLList = lst[i].children();
for(var j:int = 0; j < x.length(); j++)
{
if(x[j].#inputtype == 'TextInput')
{
var frmItem:FormItem = new FormItem();
//frmItem.direction = "horizontal";
frmItem.label = x[j].#formlabel;
// make sure boolean is pasrsed to a string before assigned
// to required property of the formitem
var validString : String = x[j].#required;
var valid : Boolean = (validString == "true");
frmItem.required = valid;
var tb:TextInput = new TextInput();
tb.text = x[j];
frmItem.addElement(tb);
userInfoForm.addElement(frmItem);
}
else if(x[j].#inputtype == 'ComboBox')
{
var frmItemCB:FormItem = new FormItem();
//frmItemCB.direction = "horizontal";
frmItemCB.label = x[j].#formlabel;
// make sure boolean is pasrsed to a string before assigned
// to required property of the formitem
var validString : String = x[j].#required;
var valid : Boolean = (validString == "true");
frmItemCB.required = valid;
// make sure the string is split, assigned to an array, and parsed
// to an arraycollection to assgn it as dataprovider for dropdownlist
var str:String = x[j];
var arr:Array = str.split(",");
var arrcol:ArrayCollection = new ArrayCollection();
for(var k:int = 0; k < arr.length; k++)
{
var obj:Object = {name:arr[k]}
arrcol.addItem(obj);
}
var cb:DropDownList = new DropDownList();
cb.dataProvider = arrcol;
cb.labelField = "name";
frmItemCB.addElement(cb);
userInfoForm.addElement(frmItemCB);
}
else if(x[j].#inputtype == 'RadioButtonGroup')
{
var frmItemRB:FormItem = new FormItem();
//frmItemRB.direction = "horizontal";
frmItemRB.label = x[j].#formlabel;
// make sure boolean is pasrsed to a string before assigned
// to required property of the formitem
var validString : String = x[j].#required;
var valid : Boolean = (validString == "true");
frmItemRB.required = valid;
var frmItemRB1:FormItem = new FormItem();
frmItemRB1.addElement(label);
var y:XMLList = x[j].children();
var radioGroup = new RadioButtonGroup();
radioGroup.addEventListener(ItemClickEvent.ITEM_CLICK,
radioGroup_itemClick);
for(var l:int = 0; l < y.length(); l++)
{
var rb = new RadioButton();
rb.label = y[l];
rb.group = radioGroup;
frmItemRB.addElement(rb);
userInfoForm.addElement(frmItemRB);
}
}
}
}
}
public var label:TextInput = new TextInput();
private function radioGroup_itemClick(evt:ItemClickEvent):void {
label.text = evt.label ;
}
/**
* Helper function that returns all the fields for a
* given form. Pass in requiredOnly = true if you only want
* the required fields.
*/
private function getFields(form:Form, requiredOnly:Boolean=false):Array
{
var a:Array = [];
return a;
}
/**
* Validates all fields in a given form.
*/
private function validateForm(form:Form):Boolean
{
// reset the flag
var _isValid:Boolean = true;
var _notValid:Boolean = false;
// populate the fields - if your fields aren't dynamic put this in creationComplete
var fields:Array = getFields(form, true);
for each(var source:UIComponent in fields)
{
// create a simple string validator
var stringValidator:StringValidator = new StringValidator();
stringValidator.minLength = 2;
stringValidator.source = source;
stringValidator.property = "text";
stringValidator.requiredFieldError = "This field is required!!!";
var numberValidator:NumberValidator = new NumberValidator();
numberValidator.minValue = 0;
numberValidator.source = source;
numberValidator.property = "text";
numberValidator.lowerThanMinError = "This field is required!!!";
var rbValidator:StringValidator = new StringValidator();
rbValidator.minLength = 1;
rbValidator.maxLength = 80;
rbValidator.source = source;
rbValidator.property = "selectedValue";
rbValidator.requiredFieldError = "This field is required!!!";
var result:ValidationResultEvent;
//var radiogroup:spark.components.RadioButtonGroup = new spark.components.RadioButtonGroup;
// typical validation, but check to this checks for any different
// types of UIComponent here
if (source is TextInput)
result = stringValidator.validate(TextInput(source).text)
else if (source is TextArea)
result = stringValidator.validate(TextArea(source).text)
else if (source is DropDownList)
result = numberValidator.validate(DropDownList(source).selectedIndex)
//else if (source is Label)
//result = stringValidator.validate(Label(source).text)
//if(source is spark.components.RadioButton)
//result = numberValidator.validate(mx.controls.RadioButton(source))
// if the source is valid, then mark the form as valid
_isValid = (result.type == ValidationResultEvent.VALID) && _isValid;
}
return _isValid;
}
protected function submitButton_clickHandler(event:MouseEvent):void
{
if(validateForm(userInfoForm) == true)
{
//Alert.show("Proceed Genius!!!","Alert");
}
else
{
//Alert.show("Open ur eyes and fill the form properly u morron!!!","Morron");
}
}
]]>
</fx:Script>
<fx:Declarations>
<!--Below line can be used for XML from an external source-->
<!--<mx:HTTPService fault="errorHandler(event)" id="XMLService" resultFormat="e4x" url="formdata.xml" result="resultHandler(event)" />-->
</fx:Declarations>
<s:VGroup width="100%">
<s:Form id="userInfoForm" />
<s:Button label="Submit" id="submitButton" click="submitButton_clickHandler(event)"/>
</s:VGroup>
</s:View>

Resources