...

View Full Version : getting 1083: Syntax error: else is unexpected



akuria
11-06-2011, 01:58 AM
i am getting this error in my code in flash builder. here is the code i have:

protected function submit_appointment_clickHandler():void
{
var Sender:String = "";
var Email:String = "";
var HomePhone:String = "";
var CellPhone:String = "";
var Address:String = "";
var City:String = "";
var State:String = "";
var ZipCode:String = "";
var Comments:String = "";
var Interests:String = "";
var Type:String = currentState;

var evValidEmail: ValidationResultEvent = emailValidator.validate();
var evValidName: ValidationResultEvent = nameValidator.validate();
var evValidCellPhone: ValidationResultEvent = cellValidator.validate();
var evValidHomePhone: ValidationResultEvent = homeValidator.validate();

if (evValidEmail.type == ValidationResultEvent.VALID
&& evValidName.type == ValidationResultEvent.VALID
&& evValidCellPhone.type == ValidationResultEvent.VALID
&& evValidHomePhone.type == ValidationResultEvent.VALID)

else{
resultLabel.text="There are Form errors";
resultLabel.setStyle("styleName", "invalid");
}
}

any help would be appreciated

_Aerospace_Eng_
11-06-2011, 03:29 PM
I see a few syntax errors in your code. Try this

protected function submit_appointment_clickHandler():void
{
var Sender:String = "";
var Email:String = "";
var HomePhone:String = "";
var CellPhone:String = "";
var Address:String = "";
var City:String = "";
var State:String = "";
var ZipCode:String = "";
var Comments:String = "";
var Interests:String = "";
var Type:String = currentState;

var evValidEmail:ValidationResultEvent = emailValidator.validate();
var evValidName:ValidationResultEvent = nameValidator.validate();
var evValidCellPhone:ValidationResultEvent = cellValidator.validate();
var evValidHomePhone:ValidationResultEvent = homeValidator.validate();

if (evValidEmail.type == ValidationResultEvent.VALID
&& evValidName.type == ValidationResultEvent.VALID
&& evValidCellPhone.type == ValidationResultEvent.VALID
&& evValidHomePhone.type == ValidationResultEvent.VALID)
{
resultLabel.text="Thank you.";
resultLabel.setStyle("styleName", "valid");
}
else
{
resultLabel.text="There are Form errors";
resultLabel.setStyle("styleName", "invalid");
}
}
Your strict data typing for ValidationResultEvent variables had a space after the : so that wouldn't work. You had an else nested inside of an if which wouldn't work either. The code above should work. If it doesn't give us the line number that the error occurs on as well.

akuria
11-06-2011, 07:10 PM
i did the changes and that error went went away only to give me another error at another spot. here is the code:

i put a mad face on the line where i am getting the error

1087: Syntax error: extra characters found after end of program.


protected function submit_appointment_clickHandler():void
{
var Sender:String = "";
var Email:String = "";
var HomePhone:String = "";
var CellPhone:String = "";
var Address:String = "";
var City:String = "";
var State:String = "";
var ZipCode:String = "";
var Comments:String = "";
var Interests:String = "";
var Type:String = currentState;

var evValidEmail:ValidationResultEvent = emailValidator.validate();
var evValidName:ValidationResultEvent = nameValidator.validate();
var evValidCellPhone:ValidationResultEvent = cellValidator.validate();
var evValidHomePhone:ValidationResultEvent = homeValidator.validate();

if (evValidEmail.type == ValidationResultEvent.VALID
&& evValidName.type == ValidationResultEvent.VALID
&& evValidCellPhone.type == ValidationResultEvent.VALID
&& evValidHomePhone.type == ValidationResultEvent.VALID)
{
resultLabel.text="Thank you.";
resultLabel.setStyle("styleName", "valid");
}
else
{
resultLabel.text="There are Form errors";
resultLabel.setStyle("styleName", "invalid");
}
}

switch(currentState)
{
case "appointment":
Sender = txtApptFirstName.text + " " + txtApptLastName.text;
Email = txtApptEmail.text;
HomePhone = txtApptHomePhone.text;
CellPhone = txtApptCellPhone.text;
Address = txtApptAddress.text;
City = txtApptCity.text;
State = txtApptState.text;
ZipCode = txtApptZipCode.text;
Comments = txtApptComments.text;
if(chkApptPhotography.selected) Interests = Interests + " Photography Session ";
if(chkApptChildrenFamily.selected) Interests = Interests + " Children and Family Portraits ";
if(chkApptPromSchool.selected) Interests = Interests + " Prom and School Event Photos ";
if(chkApptSeniorSchool.selected) Interests = Interests + " Senior School Photos ";
break;
case "contact":
Sender = txtContactFirstName.text + " " + txtContactLastName.text;
Email = txtContactEmail.text;
HomePhone = txtContactHomePhone.text;
CellPhone = txtContactCellPhone.text;
Address = txtContactAddress.text;
City = txtContactCity.text;
State = txtContactState.text;
ZipCode = txtContactZipCode.text;
Comments = txtContactComments.text;
if(chkContactPhotography.selected) Interests = Interests + " Photography Session ";
if(chkContactChildrenFamily.selected) Interests = Interests + " Children and Family Portraits ";
if(chkContactPromSchool.selected) Interests = Interests + " Prom and School Event Photos ";
if(chkContactSeniorSchool.selected) Interests = Interests + " Senior School Photos ";
break;
case "free_shoot":
Sender = txtFreeFirstName.text + " " + txtFreeLastName.text;
Email = txtFreeEmail.text;
HomePhone = txtFreeHomePhone.text;
CellPhone = txtFreeCellPhone.text;
Comments = txtFreeComments.text;
break;
}

emailService.send(
{
senderName: Sender,
senderEmail: Email,
senderHomePhone: HomePhone,
senderCellPhone: CellPhone,
senderAddress: Address,
senderCity: City,
senderState: State,
senderZipCode: ZipCode,
senderComments: Comments,
senderInterests: Interests,
sendType: Type
});
}:mad:


private function emailResult():void
{
Alert.show("Thank you for your submission. You will contacted shortly.");
clearForm();
}


private function clearForm():void
{
txtFreeFirstName.text="";
txtFreeLastName.text="";
txtFreeEmail.text="";
txtFreeHomePhone.text="";
txtFreeCellPhone.text="";
txtFreeComments.text="";

txtApptFirstName.text="";
txtApptLastName.text="";
txtApptEmail.text="";
txtApptHomePhone.text="";
txtApptCellPhone.text="";
txtApptAddress.text="";
txtApptCity.text="";
txtApptState.text="";
txtApptZipCode.text="";
txtApptComments.text="";
chkApptPhotography;
chkApptChildrenFamily;
chkApptPromSchool;
chkApptSeniorSchool;

txtContactFirstName.text="";
txtContactLastName.text="";
txtContactEmail.text="";
txtContactHomePhone.text="";
txtContactCellPhone.text="";
txtContactAddress.text="";
txtContactCity.text="";
txtContactState.text="";
txtContactZipCode.text="";
txtContactComments.text="";
chkContactPhotography;
chkContactChildrenFamily;
chkContactPromSchool;
chkContactSeniorSchool;
}

_Aerospace_Eng_
11-07-2011, 12:23 AM
I didn't know you had more code. It helps to post all of your code. In the future please do so. Remove the last } after this

if (evValidEmail.type == ValidationResultEvent.VALID
&& evValidName.type == ValidationResultEvent.VALID
&& evValidCellPhone.type == ValidationResultEvent.VALID
&& evValidHomePhone.type == ValidationResultEvent.VALID)
{
resultLabel.text="Thank you.";
resultLabel.setStyle("styleName", "valid");
}
else
{
resultLabel.text="There are Form errors";
resultLabel.setStyle("styleName", "invalid");
}
}

akuria
11-07-2011, 01:43 AM
now i am getting error messages at the resultLabel lines (x4) here is my entire bit of code so no hopefully no more errors. lol. thanks for the info and help so far.

1120: Access of undefined property resultLabel.


<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.events.ValidationResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.SOAPFault;
import mx.rpc.soap.WebService;
protected function button_clickHandler():void
{
currentState='home';
Sequence1.play();
}
protected function button_clickHandler_2():void
{
currentState='contact';
}
protected function button_clickHandler_1():void
{
currentState='about_team';
}
protected function button_clickHandler_14():void
{
currentState='about_what';
}
protected function button_clickHandler_15():void
{
currentState='about_who';
}
protected function button_clickHandler_16():void
{
currentState='about_team';
}
protected function button_clickHandler_19():void
{
currentState='appointment';
}
protected function button_clickHandler_20():void
{
currentState='service';
}
protected function button_clickHandler_21():void
{
navigateToURL( new URLRequest( encodeURI("http://protegefoundation.org")), "_blank");
}
protected function button_clickHandler_24():void
{
currentState='testimonial';
}
protected function button_clickHandler_25():void
{
currentState='charity';
}
protected function button_clickHandler_3():void
{
currentState='studio_tour';
Sequence4.play();
}
protected function button_clickHandler_4():void
{
currentState='galleries';
}
protected function button_clickHandler_7():void
{
currentState='packages';
}
protected function button_clickHandler_8():void
{
currentState='shop';
}
protected function button_clickHandler_17():void
{
currentState='free_shoot';
}
protected function button_clickHandler_18():void
{
currentState='appointment';
}























protected function submit_appointment_clickHandler():void
{
var Sender:String = "";
var Email:String = "";
var HomePhone:String = "";
var CellPhone:String = "";
var Address:String = "";
var City:String = "";
var State:String = "";
var ZipCode:String = "";
var Comments:String = "";
var Interests:String = "";
var Type:String = currentState;

var evValidEmail:ValidationResultEvent = emailValidator.validate();
var evValidName:ValidationResultEvent = nameValidator.validate();
var evValidCellPhone:ValidationResultEvent = cellValidator.validate();
var evValidHomePhone:ValidationResultEvent = homeValidator.validate();

if (evValidEmail.type == ValidationResultEvent.VALID
&& evValidName.type == ValidationResultEvent.VALID
&& evValidCellPhone.type == ValidationResultEvent.VALID
&& evValidHomePhone.type == ValidationResultEvent.VALID)
{
resultLabel.text="Thank you.";
resultLabel.setStyle("styleName", "valid");
}
else
{
resultLabel.text="There are Form errors";
resultLabel.setStyle("styleName", "invalid");
}

switch(currentState)
{
case "appointment":
Sender = txtApptFirstName.text + " " + txtApptLastName.text;
Email = txtApptEmail.text;
HomePhone = txtApptHomePhone.text;
CellPhone = txtApptCellPhone.text;
Address = txtApptAddress.text;
City = txtApptCity.text;
State = txtApptState.text;
ZipCode = txtApptZipCode.text;
Comments = txtApptComments.text;
if(chkApptPhotography.selected) Interests = Interests + " Photography Session ";
if(chkApptChildrenFamily.selected) Interests = Interests + " Children and Family Portraits ";
if(chkApptPromSchool.selected) Interests = Interests + " Prom and School Event Photos ";
if(chkApptSeniorSchool.selected) Interests = Interests + " Senior School Photos ";
break;
case "contact":
Sender = txtContactFirstName.text + " " + txtContactLastName.text;
Email = txtContactEmail.text;
HomePhone = txtContactHomePhone.text;
CellPhone = txtContactCellPhone.text;
Address = txtContactAddress.text;
City = txtContactCity.text;
State = txtContactState.text;
ZipCode = txtContactZipCode.text;
Comments = txtContactComments.text;
if(chkContactPhotography.selected) Interests = Interests + " Photography Session ";
if(chkContactChildrenFamily.selected) Interests = Interests + " Children and Family Portraits ";
if(chkContactPromSchool.selected) Interests = Interests + " Prom and School Event Photos ";
if(chkContactSeniorSchool.selected) Interests = Interests + " Senior School Photos ";
break;
case "free_shoot":
Sender = txtFreeFirstName.text + " " + txtFreeLastName.text;
Email = txtFreeEmail.text;
HomePhone = txtFreeHomePhone.text;
CellPhone = txtFreeCellPhone.text;
Comments = txtFreeComments.text;
break;
}

emailService.send(
{
senderName: Sender,
senderEmail: Email,
senderHomePhone: HomePhone,
senderCellPhone: CellPhone,
senderAddress: Address,
senderCity: City,
senderState: State,
senderZipCode: ZipCode,
senderComments: Comments,
senderInterests: Interests,
sendType: Type
});
}


private function emailResult():void
{
Alert.show("Thank you for your submission. You will contacted shortly.");
clearForm();
}


private function clearForm():void
{
txtFreeFirstName.text="";
txtFreeLastName.text="";
txtFreeEmail.text="";
txtFreeHomePhone.text="";
txtFreeCellPhone.text="";
txtFreeComments.text="";

txtApptFirstName.text="";
txtApptLastName.text="";
txtApptEmail.text="";
txtApptHomePhone.text="";
txtApptCellPhone.text="";
txtApptAddress.text="";
txtApptCity.text="";
txtApptState.text="";
txtApptZipCode.text="";
txtApptComments.text="";
chkApptPhotography;
chkApptChildrenFamily;
chkApptPromSchool;
chkApptSeniorSchool;

txtContactFirstName.text="";
txtContactLastName.text="";
txtContactEmail.text="";
txtContactHomePhone.text="";
txtContactCellPhone.text="";
txtContactAddress.text="";
txtContactCity.text="";
txtContactState.text="";
txtContactZipCode.text="";
txtContactComments.text="";
chkContactPhotography;
chkContactChildrenFamily;
chkContactPromSchool;
chkContactSeniorSchool;
}



protected function button_clickHandler_5():void
{
currentState='career';
}


protected function button_clickHandler_6():void
{
navigateToURL( new URLRequest( encodeURI("mailto:info@protege.tv")), "_self");
}


protected function button_clickHandler_9():void
{
navigateToURL( new URLRequest( encodeURI("http://protege.tv/pdf/PROTEGE_MAP_DIRECTION.pdf")), "_self");
}


protected function button_clickHandler_10():void
{
currentState='map';
}


protected function swfcontroller2_completeHandler(event:Event):void
{
Sequence4.play();
}

protected function swfcontroller1_completeHandler(event:Event):void
{
Sequence1.play();
}

]]></fx:Script>
<s:states>
<s:State fc:color="0xcc0000" name="home"/>
<s:State fc:color="0x0081cc" name="contact"/>
<s:State fc:color="0x00cc21" name="about_team"/>
<s:State fc:color="0xa30017" name="about_what"/>
<s:State fc:color="0x08ffb6" name="about_who"/>
<s:State fc:color="0x510900" name="free_shoot"/>
<s:State fc:color="0xbbcc00" name="appointment"/>
<s:State fc:color="0x9308ff" name="service"/>
<s:State fc:color="0x157100" name="charity"/>
<s:State fc:color="0xa30096" name="testimonial"/>
<s:State fc:color="0x00a38e" name="studio_tour"/>
<s:State fc:color="0xfe4f8d" name="packages"/>
<s:State fc:color="0xcca3ff" name="galleries"/>
<s:State fc:color="0xcc0000" name="shop"/>
<s:State name="career"/>
<s:State name="map"/>
</s:states>
<fx:Declarations>
<mx:HTTPService id="emailService"
url="sendEmail.php"
method="POST"
resultFormat="xml"
result="emailResult()"
useProxy="false"/>
<mx:EmailValidator id="emailValidator"
source="{txtFreeEmail, txtApptEmail, txtContactEmail}" property="text"
requiredFieldError="Enter your email" required="true" />
<mx:StringValidator id="nameValidator"
source="{txtFreeFirstName, txtFreeLastName, txtApptFirstName, txtApptLastName, txtContactFirstName, txtContactLastName}" property="text"
requiredFieldError="Enter your name" required="true"/>
<mx:StringValidator id="cellValidator"
source="{txtFreeCellPhone, txtApptCellPhone, txtContactCellPhone}" property="text"
requiredFieldError="Enter your cell phone number" required="true"/>
<mx:StringValidator id="homeValidator"
source="{txtFreeHomePhone, txtApptHomePhone, txtContactHomePhone}" property="text"
requiredFieldError="Enter your home phone number" required="true"/>
<s:Parallel id="Sequence1">
<s:Parallel target="{swfcontroller1}">
<s:CallAction functionName="playSWF"/>
</s:Parallel>
</s:Parallel>
<s:Parallel id="Sequence3">
</s:Parallel>
<s:Parallel id="Sequence4">
<s:Parallel target="{swfcontroller2}">
<s:CallAction functionName="playSWF"/>
</s:Parallel>
</s:Parallel>
</fx:Declarations>

_Aerospace_Eng_
11-09-2011, 02:47 AM
Read the error. It is telling you exactly what the problem is. Where is resultLabel defined?

akuria
11-09-2011, 03:16 AM
Read the error. It is telling you exactly what the problem is. Where is resultLabel defined?

duh! thanks. i added the define line of code and no errors but its not working.


<mx:Label id="resultLabel"/>

i added this line of code to the declarations area of the code.

_Aerospace_Eng_
11-09-2011, 03:25 AM
Okay that is fine and all but what are you going to do with it? You haven't added it to the timeline or anything.

akuria
11-09-2011, 04:10 AM
Okay that is fine and all but what are you going to do with it? You haven't added it to the timeline or anything.

what do you mean? sorry i am a noob to flex.

_Aerospace_Eng_
11-09-2011, 07:19 AM
Where are you using resultLabel? You aren't displaying it anywhere.

akuria
11-09-2011, 08:03 AM
Where are you using resultLabel? You aren't displaying it anywhere.

this is where i am using the resultLabel.


protected function submit_appointment_clickHandler():void
{
var Sender:String = "";
var Email:String = "";
var HomePhone:String = "";
var CellPhone:String = "";
var Address:String = "";
var City:String = "";
var State:String = "";
var ZipCode:String = "";
var Comments:String = "";
var Interests:String = "";
var Type:String = currentState;

var evValidEmail:ValidationResultEvent = emailValidator.validate();
var evValidName:ValidationResultEvent = nameValidator.validate();
var evValidCellPhone:ValidationResultEvent = cellValidator.validate();
var evValidHomePhone:ValidationResultEvent = homeValidator.validate();

if (evValidEmail.type == ValidationResultEvent.VALID
&& evValidName.type == ValidationResultEvent.VALID
&& evValidCellPhone.type == ValidationResultEvent.VALID
&& evValidHomePhone.type == ValidationResultEvent.VALID)
{
resultLabel.text="Thank you.";
resultLabel.setStyle("styleName", "valid");
}
else
{
resultLabel.text="There are Form errors";
resultLabel.setStyle("styleName", "invalid");
}

switch(currentState)
{
case "appointment":
Sender = txtApptFirstName.text + " " + txtApptLastName.text;
Email = txtApptEmail.text;
HomePhone = txtApptHomePhone.text;
CellPhone = txtApptCellPhone.text;
Address = txtApptAddress.text;
City = txtApptCity.text;
State = txtApptState.text;
ZipCode = txtApptZipCode.text;
Comments = txtApptComments.text;
if(chkApptPhotography.selected) Interests = Interests + " Photography Session ";
if(chkApptChildrenFamily.selected) Interests = Interests + " Children and Family Portraits ";
if(chkApptPromSchool.selected) Interests = Interests + " Prom and School Event Photos ";
if(chkApptSeniorSchool.selected) Interests = Interests + " Senior School Photos ";
break;
case "contact":
Sender = txtContactFirstName.text + " " + txtContactLastName.text;
Email = txtContactEmail.text;
HomePhone = txtContactHomePhone.text;
CellPhone = txtContactCellPhone.text;
Address = txtContactAddress.text;
City = txtContactCity.text;
State = txtContactState.text;
ZipCode = txtContactZipCode.text;
Comments = txtContactComments.text;
if(chkContactPhotography.selected) Interests = Interests + " Photography Session ";
if(chkContactChildrenFamily.selected) Interests = Interests + " Children and Family Portraits ";
if(chkContactPromSchool.selected) Interests = Interests + " Prom and School Event Photos ";
if(chkContactSeniorSchool.selected) Interests = Interests + " Senior School Photos ";
break;
case "free_shoot":
Sender = txtFreeFirstName.text + " " + txtFreeLastName.text;
Email = txtFreeEmail.text;
HomePhone = txtFreeHomePhone.text;
CellPhone = txtFreeCellPhone.text;
Comments = txtFreeComments.text;
break;
}

emailService.send(
{
senderName: Sender,
senderEmail: Email,
senderHomePhone: HomePhone,
senderCellPhone: CellPhone,
senderAddress: Address,
senderCity: City,
senderState: State,
senderZipCode: ZipCode,
senderComments: Comments,
senderInterests: Interests,
sendType: Type
});
}

and here is where i am declaring it


<fx:Declarations>
<mx:Label id="resultLabel"/>
<mx:HTTPService id="emailService"
url="sendEmail.php"
method="POST"
resultFormat="xml"
result="emailResult()"
useProxy="false"/>
<mx:EmailValidator id="emailValidator"
source="{txtFreeEmail, txtApptEmail, txtContactEmail}" property="text"
requiredFieldError="Enter your email" required="true" />
<mx:StringValidator id="nameValidator"
source="{txtFreeFirstName, txtFreeLastName, txtApptFirstName, txtApptLastName, txtContactFirstName, txtContactLastName}" property="text"
requiredFieldError="Enter your name" required="true"/>
<mx:StringValidator id="cellValidator"
source="{txtFreeCellPhone, txtApptCellPhone, txtContactCellPhone}" property="text"
requiredFieldError="Enter your cell phone number" required="true"/>
<mx:StringValidator id="homeValidator"
source="{txtFreeHomePhone, txtApptHomePhone, txtContactHomePhone}" property="text"
requiredFieldError="Enter your home phone number" required="true"/>
<s:Parallel id="Sequence1">
<s:Parallel target="{swfcontroller1}">
<s:CallAction functionName="playSWF"/>
</s:Parallel>
</s:Parallel>
<s:Parallel id="Sequence3">
</s:Parallel>
<s:Parallel id="Sequence4">
<s:Parallel target="{swfcontroller2}">
<s:CallAction functionName="playSWF"/>
</s:Parallel>
</s:Parallel>
</fx:Declarations>

_Aerospace_Eng_
11-09-2011, 11:50 PM
I guess I'm not too familiar with how flex apps work. Don't you have to tell flex where to display the label?

akuria
11-10-2011, 09:20 AM
I don't know. I guess that's why i am asking.

Inigoesdr
11-13-2011, 04:29 AM
You don't put display elements in the Declarations tag like that; they would go in a Group/HGroup/VGroup that is your main content body, or some other element you are adding. The Declarations tag is for non-visible elements like services, validators, and effects.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum