Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Creating a First Web Site with Flash Professional CS5 shows how to make a fully functional, dynamic web site in Flash Professional CS5. This course covers the fundamentals of creating and importing content, adding smooth 2D and 3D transitions, and adding button functionality that goes beyond links. This course will also show how to integrate and control video and audio as well as how to implement a gallery and a contact form. Exercise files are included with the course.
Once you have your input text fields in place, you then need to check to make sure the user actually entered in information in these fields before sending out the information. So I'm going to select this contact form right here. I'll just double click on it, so I'm inside of this Contact movie clip. And let's just confirm a couple of these instance names. For this first text field, it is called theName, then we have theEmail, then we have theMessage.
So those are the three text fields that I'm just going to check when you click on the Send button. But really what I need to do is I need to take this graphic and convert it into a button. So I'll just select a graphic, drag it into the Library, and let's call it send button, make sure the Type is of Button, and I'll click OK. All right, with that button still selected, I can give it an instance name of send_btn. Okay, so when you click on send_btn, I want to just check those fields.
So I'm going to use code snippets to get me started with the code structure. So, in the Code Snippets panel, under Event Handlers, I'm just going to add a Mouse Click Event. So I'll just double-click on that, and I just added the mouse click event to the Send button, and it just traces out the "Mouse Clicked." Well, I don't really want to do that. What I want to do is I want to check or at least get the information in those text fields. So what I can do is I can type in theName.text, just like that, and that will enable me to see whatever is in that text field.
Okay, I'm just going to copy this line, paste it below twice, because I want to get theEmail and theMessage, just like that. So, when they click on the Send button, trace out whatever is in these three fields. I'm going to get the text in them and what it's going to do is it's going to appear in my Output panel. So with that set up, all I'm going to do is I'm just going to test out this movie to make sure it's working.
(Music playing) Just like that. I've entered an information in there and if I click the Send button, I should see in the Output panel this text, and there it is. So again, my trace statement actually sort of prints out that information, places it in my Output panel. All right. So that next step is to go ahead and make sure the user actually entered in information into those three fields. And even if they did, what I want to do is display a nice message right next of the Send button.
So close this file, go back into my code, and I'm going to go ahead and write in place of this comment, I'm going to go ahead and add an If statement. So, here is the basic If statement structure. It's going to look just like this. I'll move this up a little bit. Open and close parenthesis. If a certain value is met, then do whatever is in these two curly braces. So, I'm going to check if theName.text is equal, I need two equal signs there, if it's equal to nothing, so if they didn't put anything in there, that's two quotes there, then display a certain message.
And what I want to do is I want to display a message right in this text field. So I need to select this text field, I'm going to go to Properties, and I need to make sure it has an instance name. So I'm going to call it theFeedback. Let me go back to that code. It's in my first frame of the Timeline here, and theFeedback, in that text field go ahead and put "Please enter in a name," just like that, within quotes.
So if there's nothing in there, then it shows me this message. Let's go and test this. (Music playing) Again, I'm not going to put anything in here. I'll just click Send, and it says "Please enter in a name." So it's working out great so far, the other thing I need to do is add in checks for these other two text fields. So I'm going to do that right now, and continue on to add some more code as well.
So theName.text, if that's equal to nothing then displays this. And what I want to do is I'm going to edit this message to say, "Please fill out all fields." So that's going to be the generic message that gets displayed anytime they do not enter in information in here. So, I'm going to add some more code in here. So, it there's nothing in theName text field or, and these are two pipes is what those are, just under the Delete key, these two pipes is an OR statement.
So, or theEmail.text is also, you know, if that's equal to nothing or theMessage.text is equal. And again, I need two equal signs right in here, because I'm doing a check to see if one thing is compared to another basically. All right, so that looks pretty good. It there is nothing in theName text field or nothing in theEmail or nothing in theMessage, then display this line.
If they do actually fill out all these fields, well, I want to add an else, open curly brace, closing curly brace gets added when I hit the Return button. else theFeedback.text, we'll just add a quick Thank you. There we go. That's perfectly fine, just some feedback and saying that they have entered in the Form, and its entirety. And what I can even do is clear it, so theName. Again, they entered in the fields correctly.
I display a thank you message and then I clear all the fields, in case they want to send another message, just like that. All right, everything now looks good. I'm going to go ahead and test this out now. (Music playing) Okay, so maybe again I did not enter anything in the Email field.
I'll click Send, and it does display that information but also says, "Please fill out all fields," and I'm like okay, well, I will. There we go. Now if I click Send, it clears the form and then gives you a thank you message as well. So now that I have this verification in place, I can then take that data and then pass it out and ultimately send this information to the person's email address.
Find answers to the most frequently asked questions about Creating a First Web Site with Flash Professional CS5.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.