> I have a form as a custom component with four text fields and two check
> boxes that I need to have the information sent to the main application. I
> have created a custom event to be able to dispatch the text from the text
> fields and display in an Alert box. For some reason it is not sending the
> text over but the event is being dispatched.
> The code is listed below:
> main.mxml:
> <mx:Script>
> <![CDATA[
> * import* mx.controls.Alert;
> * import* events.FormEvent;
> [*Bindable*]
> * private* *var* firstNameInput:String = *new* String;
> * private* *var* lastNameInput:String = *new* String;
> * private* *var* emailAddressInput:String = *new* String;
> * private* *var* stateInput:String = *new* String;
> * private* *var* countryInput:String = *new* String;
> * private* *var* newsletterCheck:Boolean = *new* Boolean;
> * private* *var* surveysCheck:Boolean = *new* Boolean;
> * *
> * private* *function* formSubmitHandler(event:FormEvent):*void* {
> firstNameInput = event.firstNameInput;
> lastNameInput = event.lastNameInput;
> emailAddressInput = event.emailAddressInput;
> Alert.show(firstNameInput);
> }
> ]]>
> </mx:Script>
> <com:form horizontalCenter="0" verticalCenter="0" id="form1"
> formSubmit="formSubmitHandler(event)"/>
> form.mxml:
> <mx:Metadata>
> [
> *Event*(name=*"formSubmit"*, type=*"events.FormEvent"*)]
> </mx:Metadata>
> <mx:Script>
> <![CDATA[
> * import* mx.rpc.events.AbstractEvent;
> * import* events.FormEvent;
> * import* mx.controls.Alert;
> * ** *
> * /**/ Create variables for form fields*
> [
> *Bindable*]
> * public* *var* firstNameInput:String;
> * public* *var* lastNameInput:String;
> * public* *var* emailAddressInput:String;
> * public* *var* stateInput:String;
> * public* *var* countryInput:String;
> * public* *var* newsletterCheck:Boolean;
> * public* *var* surveysCheck:Boolean;
> **
> * // Function to handle the form submissions*
> * private* *function* submitForm():*void* {
> * //customEventHandler(event);*
> }
> **
> * private* *function* dispatchEventHandler(event:FormEvent):*void* {
> * var* formObj:FormEvent = *new* FormEvent(firstNameInput,
> lastNameInput, emailAddressInput);
> formObj.firstNameInput = firstname.text;
> formObj.lastNameInput = lastname.text;
> formObj.emailAddressInput = email.text;
> dispatchEvent(formObj);
> }
> ]]>
> </mx:Script>
> <mx:VBox
> id="Panel">
> <mx:Form>
> <mx:HBox width="100%">
> <mx:FormItem required="true" label="First Name">
> <mx:TextInput id="firstname"/>
> </mx:FormItem>
> <mx:FormItem required="true" label="Last Name">
> <mx:TextInput id="lastname"/>
> </mx:FormItem>
> </mx:HBox>
> <mx:HBox width="100%">
> <mx:FormItem label="Email" required="true">
> <mx:TextInput id="email" />
> </mx:FormItem>
> <mx:FormItem label="State">
> <mx:TextInput id="state"/>
> </mx:FormItem>
> <mx:FormItem label="Country">
> <mx:TextInput id="country"/>
> </mx:FormItem>
> </mx:HBox>
> <mx:HBox>
> <mx:FormItem label="" required="false">
> <mx:CheckBox id="enewsletter"/>
> </mx:FormItem>
> </mx:HBox>
> <mx:HBox width="100%">
> <mx:FormItem label="" required="false">
> <mx:CheckBox id="surveys" />
> </mx:FormItem>
> </mx:HBox>
> </mx:Form>
> <mx:Button label="Submit Details" click="submitForm()" id="submitButton"
> />
> </mx:VBox>
> FormEvent.as:
> *
> package
> * events
> {
> * import* flash.events.Event;
> * public* *class* FormEvent *extends* Event
> {
> * public* *var* firstNameInput:String;
> * public* *var* lastNameInput:String;
> * public* *var* emailAddressInput:String;
> * *
> * public* *function* FormEvent(type:String, firstNameInput:String=*""
> *, lastNameInput:String=*""*,
> emailAddressInput:String=*""*)
> {
> * super*(type);
> * this*.firstNameInput = firstNameInput;
> * this*.lastNameInput = lastNameInput;
> * this*.emailAddressInput = emailAddressInput;
> }
> * override* *public* *function* clone():Event
> {
> * return* *new* FormEvent(type, firstNameInput, lastNameInput,
> emailAddressInput);
> }
> }
> }
> Brad Cedergren
> http://www.bradcedergren.com
> ------------------------------
> Windows 7: It works the way you want. Learn more.<http://www.microsoft.com/Windows/windows-7/default.aspx?ocid=PID24727...>