** Noob to Flex, Old to programming **
for
http://mymiddlenameshussein.com I created a form to capture names. I
would ALSO like to read those names from the website (randomly) and combine
them with the middle name Hussein (ala Barak Obama) and have them appear
individually at the bottom, scroll to the top and then disappear, ala the
opening in Star Wars.
I created a custom HBox that has a text box for each of firstname, the middle
name constant "Hussein" and lastname. I have gotten an individual Hbox to do
the needed behavior.
I have tried several different methods (instantiate on the fly, array) and
except for instantiating 1 Hbox which does what it is "supposed to" by having
the effect occur on creation, I have been unsuccessful.
In attempting to call the instantiation code based on the timer, I saw nothing
and in the attempt to have individual components stored in an array made
visible (attaching the effect to showEffect) I saw nothing. (see attached code)
Am I not doing Timer correctly? Am I handling the multiple objects
incorrectly? Any direction (link to example? ideas?) would be greatly
appreciated. I have read a lot, but most array information is in re: to data
binding. Perchance this could be better done in Flash, but I am more of a
developer than a designer so am, in general, more comfortable with the idea of
Flex and would prefer to do it there.
Learning a lot!
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
color="#FFFFFF"
applicationComplete="currentState='addname';getCou nt();TimerExample();"
borderColor="#000101"
xmlns:ncmb="*">
<mx:HTTPService id="sendData"
url="http://mymiddlenameshussein.com/repos/hdataad d.php"
resultFormat="text" useProxy="false"
result="handlePlain(event);" fault="handleFault(event);">
<mx:request xmlns="">
<firstname>
{myfirstname.text}
</firstname>
<lastname>
{mylastname.text}
</lastname>
</mx:request>
</mx:HTTPService>
<mx:StringValidator
id="firstnameValidator"
source="{myfirstname}"
property="text"
minLength="2"
/>
<mx:StringValidator
id="lastnameValidator"
source="{mylastname}"
property="text"
minLength="2"
/>
<mx:Model id="recordCount">
<root>
<totalRecords>
0
</totalRecords>
</root>
</mx:Model>
<mx:Script>
<![CDATA[
import mx.effects.Fade;
import mx.effects.Move;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
import mx.events.ValidationResultEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
private var vResult:ValidationResultEvent;
public function handlePlain(event:ResultEvent):void
{
recordCount.totalRecords = event.result.toString();
}
public function handleFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString, "Error");
}
private function allValid():Boolean {
var IsGood: Boolean;
IsGood = true;
vResult =firstnameValidator.validate();
if (vResult.type==ValidationResultEvent.INVALID)
IsGood = false;
vResult =lastnameValidator.validate();
if (vResult.type==ValidationResultEvent.INVALID)
IsGood = false;
return IsGood;
}
private function getCount(): void {
myfirstname.text = 'GETCOUNT';
sendData.send();
// recordCount.totalRecords = sendData.lastResult.recordcount.record;
myfirstname.text = '';
}
private function addDataClick(): void {
var DialogMessage: String;
if (! allValid()) return;
sendData.send();
recordCount.totalRecords = sendData.lastResult.toString();
DialogMessage = myfirstname.text + ' Hussein '+ mylastname.text +
' has been added!';
showDialog(DialogMessage);
mylastname.text='';
myfirstname.text='';
currentState='addname';
}
private function showDialog(MyDialog: String) : void {
Alert.show(MyDialog, 'You have been added'); // popup modal dialog
}
public function TimerExample():void {
var myTimer:Timer = new Timer(1000, 2);
myTimer.addEventListener("timer", timerHandler);
myTimer.start();
}
private var I:int = 0;
public function timerHandler(event:TimerEvent):void {
if ( currentState=="addname"){
(namesArray[i]as nameCombiner).firstName="Doug";
(namesArray[i]as nameCombiner).lastName="Johnson"+I;
(namesArray[i]as nameCombiner).y=200;
(namesArray[i]as nameCombiner).visible=true;
I=I+1;
if (I==5){I=0;}
}
}
]]>
</mx:Script>
<mx:states>
<mx:State name="addname">
<mx:AddChild position="lastChild">
<mx:Form x="10" y="68" width="428" height="129" id="addform"
horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:FormHeading label="My Middle Name's Hussein"
color="#0A0B0A" textAlign="left" width="387"/>
<mx:FormItem label="My First Name" color="#0D0C0C">
<mx:TextInput id="myfirstname" width="290"/>
</mx:FormItem>
<mx:FormItem label="My Last Name" color="#0D0C0C">
<mx:TextInput id="mylastname" width="290"/>
</mx:FormItem>
<mx:Button id="gotomain" label="Add My Name to the List"
width="239"
color="#0E0F0D" click="addDataClick()"/>
</mx:Form>
</mx:AddChild>
<mx:RemoveChild target="{gotoadd}"/>
</mx:State>
</mx:states>
<mx:Button x="178.5" y="348" label="Add me to the list"
click="currentState='addname'" id="gotoadd"/>
<mx:Text x="22" y="10" text="{recordCount.totalRecords} have the middle name
Hussein" width="412" textAlign="center" id="howManyText" fontSize="18"/>
<mx:Array id="namesArray">
<ncmb:nameCombiner visible="false"/>
<ncmb:nameCombiner visible="false"/>
<ncmb:nameCombiner visible="false"/>
<ncmb:nameCombiner visible="false"/>
<ncmb:nameCombiner visible="false"/>
<ncmb:nameCombiner visible="false"/>
</mx:Array>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%"
height="50" horizontalGap="140"
horizontalAlign="center" verticalAlign="middle"
alpha="0.0" themeColor="#009DFF"
fontFamily="Verdana" fontSize="16" color="#000000"
showEffect="driftUp" >
<mx:Script>
<![CDATA[
override protected function commitProperties():void{
super.commitProperties();
var resize:Boolean = false;
if (this.firstName != this.firstName) {resize = true;}
if (this.lastName != this.lastName) {resize = true;}
if (this.width != this.width) {resize = true;}
// if (resize) {this.horizontalgap =
// "{((this.width -
(firstNameText.width+lastNameText.width))/2)}";}
}
]]>
</mx:Script>
<mx:String id="firstName">First</mx:String>
<mx:String id="lastName">Last</mx:String>
<mx:Sequence id="driftUp">
<mx:Fade/>
<mx:Move yTo="0" duration="10000"/>
<mx:Fade alphaFrom="1" alphaTo="0"/>
</mx:Sequence>
<mx:Text id="firstNameText" text="{firstName}"/>
<mx:Text text="Hussein"/>
<mx:Text id="lastNameText" text="{lastName}"/>
</mx:HBox>