Handling Errors
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Handling Errors < Day Day Up >Handling ErrorsDifferent projects require varying solutions for handling the errors that the validationprocess brings to light. In some cases, you may want to provide a graphical indicator suchas a red X next to the field containing the error; in others, a text message may suffice.The conditional statement within the validation routine usually determines how to handleany error that it detects. Take, for example, the following:if (dataValid) { // perform these actions} else { // Execute action to denote an error}Because error handling plays a major role in the validation process, you should thinkabout how you want to handle errors in a particular project or situation before you scriptanything else.In this exercise, well lay the foundation for the error-handling process in our project. 1. Open validate1.fla in the Lesson13/Assets folder. This project contains two frame labels: Registration and Confirm. Well work on the Confirm label in a later exercise; for now, well concentrate on the Registration label, which includes a form that the user must fill out, and thus data that needs to be validated. The timeline contains six layers named according to their content: o The Background layer contains the projects static graphical content. o The Text Components layer contains four TextInput component instances named name_ti, email_ti, state_ti, and zip_ti; and a List component instance named errorLog_lb. The TextInput instances allow the user to input name, email address, and so forth. The List component instance will be used to display any error messages generated during the forms validation process. o The Button Components layer contains two button component instances named clear_pb and submit_pb—the former will be used to clear all form fields of data; the latter will be used to submit the form, thus initiating our applications form validation process. o The Confirm Field layer contains a text field that well discuss in a later exercise. o The Actions layer will contain all the scripts for this application. o The Labels layer contains two frame labels (Registration and Confirm) to represent the applications two states: one containing the registration form, the other containing a thank you message. All of the scripting for this project will take place at the Registration label. In a later exercise, well script the application to move to the Confirm label when the user has completed the registration form accurately.2. With the Actions panel open, select Frame 1 on the Actions layer and add the following script:3.4. stop();5.6. var errors:Array = new Array();7. The first action prevents the timeline from moving beyond Frame 1 until we instruct it to do so. The second action creates an array named errors that will hold error messages to be displayed as the result of the validation process. (Well explain this in more detail as we move forward.)3. Add the following function definition at the end of the current script:4.5. function clearForm() {6.7. name_ti.text = ;8.9. email_ti.text = ;10.11. state_ti.text = ;12.13. zip_ti.text = ;14.15. errorLog_lb.removeAll();16.17. errors.length = 0;18.19. errorLog_lb.alternatingRowColors = null;20.21. }22. When called, this function resets the value of scene elements. First we remove any text that has been entered into the four TextInput instances. The next line uses the removeAll() method of the List component to remove any error messages displayed in the errorLog_lb instance. The next line removes any error messages stored in the errors array. The last line sets the alternatingRowColors property of the errorLog_lb instance to null. What does this do, and why are we doing it? Setting the alternatingRowColors property of a List component instance allows you to configure the instance to display items shown in the list with alternating row colors. This is done by creating an array with two or more color values and then setting that array as the value of the alternatingRowColors property, such as the following: var myArray:Array = new Array(0xFFCC00, 0xCC9900, 0x003366); myList_lb.alternatingRowColor = myArray; Later in this lesson we will script the errorLog_lb instance to display error messages using alternating row colors. When the form is cleared using this function, we want the errorLog_lb instance to revert back to its original all-white row colors. Setting the alternatingRowColors property to null, as this function does, takes care of that requirement. In the end, the scene will be reset to its original state.4. With the Actions panel still open, add the following script:5.6. clear_pb.addEventListener(click, clearForm);7. This script calls the clearForm() function when the clear_pb instance is clicked.5. Save this file as validate2.fla. Well build on this file throughout this lesson. The most important aspect of this exercise was the creation of the errors array, which will play a major role in the way our application handles any errors it detects in the validation process. < Day Day Up >
Tìm kiếm theo từ khóa liên quan:
máy tính mạng máy tính internet phần mềm ứng dụng lập trình SQL HTML sever web XMLTài liệu cùng danh mục:
-
Tìm hiểu về lỗi tràn bộ đệm (Buffer Overflow)
5 trang 364 0 0 -
Giáo trình Cấu trúc dữ liệu và thuật toán trên C++
74 trang 345 0 0 -
Bài giảng Phân tích thiết kế phần mềm: Chương 7 - Trường ĐH Ngoại ngữ - Tin học TP.HCM
16 trang 335 0 0 -
180 trang 274 0 0
-
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 253 0 0 -
173 trang 248 2 0
-
Bài giảng Phân tích thiết kế và giải thuật - Chương 2: Kỹ thuật thiết kế giải thuật
80 trang 245 0 0 -
Kiến thức phần cứng máy tính - Sửa chữa nâng cấp và cài đặt máy tính xách tay Tập 2
483 trang 243 3 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 243 0 0 -
Bài giảng Phân tích thiết kế phần mềm: Chương 6 - Trường ĐH Ngoại ngữ - Tin học TP.HCM
12 trang 240 0 0
Tài liệu mới:
-
Đề thi học kì 1 môn Lịch sử và Địa lí lớp 4 năm 2023-2024 có đáp án - Trường Tiểu học Đại Thịnh B
4 trang 0 0 0 -
19 trang 0 0 0
-
58 trang 0 0 0
-
7 trang 0 0 0
-
Đề thi học kì 1 môn Tiếng Việt lớp 1 năm 2024-2025 có đáp án - Trường TH Thị trấn Vĩnh Bảo
4 trang 0 0 0 -
Đề thi học kì 1 môn GDCD lớp 7 năm 2024-2025 - Trường THCS Việt Hưng, Long Biên
4 trang 0 0 0 -
9 trang 0 0 0
-
117 trang 0 0 0
-
116 trang 0 0 0
-
26 trang 0 0 0