Using The LoadVars Class
Số trang: 16
Loại file: pdf
Dung lượng: 35.87 KB
Lượt xem: 6
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Sử dụng The Class LoadVars Bạn sử dụng lớp LoadVars khi làm việc với dữ liệu ở định dạng chuỗi URL. lớp học này cho phép bạn tải dữ liệu biến từ một tập tin văn bản, hoặc để gửi và tải dữ liệu đến và từ biến một kịch bản phía máy chủ. Chú ý khi biến dữ liệu chứa trong một tập tin văn bản có thể được nạp vào Flash, Flash không thể lưu dữ liệu vào văn bản một tập tin trực tiếp, bạn phải sử dụng một kịch bản phía máy chủ để làm điều...
Nội dung trích xuất từ tài liệu:
Using The LoadVars Class < Day Day Up >Using The LoadVars ClassYou use the LoadVars class when working with data in the URL string format. This classenables you to load variable data from a text file, or to send and load variable data to andfrom a server-side script.NOTEWhile variable data contained in a text file can be loaded into Flash, Flash cannot savedata to a text file directly; you must use a server-side script to do that.Creating a LoadVars object in Flash is simple. Look at the following example:var container:LoadVars = new LoadVars();This creates a new LoadVars object named container. To load variables from a URL intoa LoadVars object, use the load() method:container.load(http://www.myDomain.com/myFile.txt);TIPYou can get the total number of bytes loaded so far or the total bytes that will be loadedby using the getBytesLoaded() and getBytesTotal() methods of the LoadVars object.When data has been loaded into a LoadVars object, you can access it by referencing thename of the particular LoadVars object that contains the data you want, followed by thevariable name of that piece of data. For example, if you were to load the following stringinto a LoadVars object named myData:name=Jobe&age=28&wife=Kellythese variable values could be referenced as follows:myData.namemyData.agemyData.wifeFor example:userAge = myData.age;Here, userAge would have a value of 28. In the same manner, a variable value in aLoadVars object can be set from within a script in Flash like this:myData.age = 45;A variable value inside a LoadVars object therefore can be set not only by loadingexternal data into the object, but by setting the value internally (using a script inside themovie).NOTEWhen loading variables into a LoadVars object, Flash will overwrite existing variablevalues in the object or append new variable values.If you want to send the variables in a LoadVars object to a server-side script forprocessing, use the send() method. That syntax is as follows:myLoadVarsObject.send(http://www.mydomain.com/process.asp);No response is sent back to Flash when you use this method, so you would use it only tosend variable data to the server for processing.The sendAndLoad() method allows you to specify a LoadVars object whose contents youwant to send, and the LoadVars object in which you want the response to load:myLoadVarsObject.sendAndLoad(http://mydomain.com/process.asp,receivingLoadVarsObject);In this case, the variables in myLoadVarsObject are sent to the specified URL forprocessing. The server sends data back to Flash, and that data is loaded intoreceivingLoadVarsObject. At that point, you can work with the receivingLoadVarsObjectto extract the data that the server sent back. If you want to send variables in a LoadVarsobject and have that same object receive the data that the server sends back, simply usethe load() method described in the following exercise.Using the toString() method of the LoadVars class, you can create a URL-formattedstring that represents the variables/values contained in the object.The LoadVars class has two properties: contentType and loaded. The contentTypeproperty can be changed before sending out variables, simply giving you the mime typespecified in the HTTP header of the loaded document. The loaded property returns true ifdata has finished loading into the object, false if it has not, and undefined if a load()method has not yet been invoked.There is only one event available to the LoadVars class: onLoad. Use this event to call afunction when data has finished loading into the object. Each time data is loaded into theobject, this event is fired again.To load variables from a specified URL into a LoadVars object and then call a functionwhen loading is complete, you must: 1. Define a function. 2. Create a new LoadVars object, using the new LoadVars constructor. 3. Specify the function to be called when the loading has completed. 4. Invoke the load() method of the LoadVars object.For example:function myFunction(){ trace(Data is loaded);}var container:LoadVars = new LoadVars();container.onLoad = myFunction;container.load(http://www.somedomain.com/myFile.asp);In this example, myFunction() is called when a string of data from the specified URL hasbeen completely loaded into the container LoadVars object.In the following exercise, youll create a simple polling system using a LoadVars object.This object will send data to and load data from an ASP page in the URL string format.The ASP page contains a server-side script that enables it to read and write to a MicrosoftAccess database. When variable data is sent to the ASP page, the page interprets the dataand updates the values in the database accordingly. When a LoadVars object requests thatdata be loaded into it from the ASP page, the page is set up so that it gets the data fromthe various fields in the database, encodes that data into the URL string format, and sendsthat data to the LoadVars object.You will find this scripted page (Poll.asp) and the accompanying database (Poll.mdb) inthe Lesson11/Assets folder on your CD-ROM. To complete this lesson successfully, youwill need access to a Windows server running IIS so that the server-side script on theASP page can be executed. Before you begin this exercise, upload Poll.asp and Poll.mdbto a Windows server and make a note of their location (URL). 1. Open poll1.fla in the Lesson 11/Assets folder. Weve already created the layers, frames, frame labels, and movie clips youll need so that you can focus on the ActionScript. With the timeline at Frame 1, youll notice the text, What was the best movie of 2003? Below this text is some space and a Submit button. You will place four Radio Button ...
Nội dung trích xuất từ tài liệu:
Using The LoadVars Class < Day Day Up >Using The LoadVars ClassYou use the LoadVars class when working with data in the URL string format. This classenables you to load variable data from a text file, or to send and load variable data to andfrom a server-side script.NOTEWhile variable data contained in a text file can be loaded into Flash, Flash cannot savedata to a text file directly; you must use a server-side script to do that.Creating a LoadVars object in Flash is simple. Look at the following example:var container:LoadVars = new LoadVars();This creates a new LoadVars object named container. To load variables from a URL intoa LoadVars object, use the load() method:container.load(http://www.myDomain.com/myFile.txt);TIPYou can get the total number of bytes loaded so far or the total bytes that will be loadedby using the getBytesLoaded() and getBytesTotal() methods of the LoadVars object.When data has been loaded into a LoadVars object, you can access it by referencing thename of the particular LoadVars object that contains the data you want, followed by thevariable name of that piece of data. For example, if you were to load the following stringinto a LoadVars object named myData:name=Jobe&age=28&wife=Kellythese variable values could be referenced as follows:myData.namemyData.agemyData.wifeFor example:userAge = myData.age;Here, userAge would have a value of 28. In the same manner, a variable value in aLoadVars object can be set from within a script in Flash like this:myData.age = 45;A variable value inside a LoadVars object therefore can be set not only by loadingexternal data into the object, but by setting the value internally (using a script inside themovie).NOTEWhen loading variables into a LoadVars object, Flash will overwrite existing variablevalues in the object or append new variable values.If you want to send the variables in a LoadVars object to a server-side script forprocessing, use the send() method. That syntax is as follows:myLoadVarsObject.send(http://www.mydomain.com/process.asp);No response is sent back to Flash when you use this method, so you would use it only tosend variable data to the server for processing.The sendAndLoad() method allows you to specify a LoadVars object whose contents youwant to send, and the LoadVars object in which you want the response to load:myLoadVarsObject.sendAndLoad(http://mydomain.com/process.asp,receivingLoadVarsObject);In this case, the variables in myLoadVarsObject are sent to the specified URL forprocessing. The server sends data back to Flash, and that data is loaded intoreceivingLoadVarsObject. At that point, you can work with the receivingLoadVarsObjectto extract the data that the server sent back. If you want to send variables in a LoadVarsobject and have that same object receive the data that the server sends back, simply usethe load() method described in the following exercise.Using the toString() method of the LoadVars class, you can create a URL-formattedstring that represents the variables/values contained in the object.The LoadVars class has two properties: contentType and loaded. The contentTypeproperty can be changed before sending out variables, simply giving you the mime typespecified in the HTTP header of the loaded document. The loaded property returns true ifdata has finished loading into the object, false if it has not, and undefined if a load()method has not yet been invoked.There is only one event available to the LoadVars class: onLoad. Use this event to call afunction when data has finished loading into the object. Each time data is loaded into theobject, this event is fired again.To load variables from a specified URL into a LoadVars object and then call a functionwhen loading is complete, you must: 1. Define a function. 2. Create a new LoadVars object, using the new LoadVars constructor. 3. Specify the function to be called when the loading has completed. 4. Invoke the load() method of the LoadVars object.For example:function myFunction(){ trace(Data is loaded);}var container:LoadVars = new LoadVars();container.onLoad = myFunction;container.load(http://www.somedomain.com/myFile.asp);In this example, myFunction() is called when a string of data from the specified URL hasbeen completely loaded into the container LoadVars object.In the following exercise, youll create a simple polling system using a LoadVars object.This object will send data to and load data from an ASP page in the URL string format.The ASP page contains a server-side script that enables it to read and write to a MicrosoftAccess database. When variable data is sent to the ASP page, the page interprets the dataand updates the values in the database accordingly. When a LoadVars object requests thatdata be loaded into it from the ASP page, the page is set up so that it gets the data fromthe various fields in the database, encodes that data into the URL string format, and sendsthat data to the LoadVars object.You will find this scripted page (Poll.asp) and the accompanying database (Poll.mdb) inthe Lesson11/Assets folder on your CD-ROM. To complete this lesson successfully, youwill need access to a Windows server running IIS so that the server-side script on theASP page can be executed. Before you begin this exercise, upload Poll.asp and Poll.mdbto a Windows server and make a note of their location (URL). 1. Open poll1.fla in the Lesson 11/Assets folder. Weve already created the layers, frames, frame labels, and movie clips youll need so that you can focus on the ActionScript. With the timeline at Frame 1, youll notice the text, What was the best movie of 2003? Below this text is some space and a Submit button. You will place four Radio Button ...
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 XMLGợi ý tài liệu liên quan:
-
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 263 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 251 1 0 -
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 244 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 244 0 0 -
47 trang 237 3 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 234 0 0 -
80 trang 216 0 0
-
122 trang 212 0 0
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 210 0 0 -
Giáo trình môn học/mô đun: Mạng máy tính (Ngành/nghề: Quản trị mạng máy tính) - Phần 1
68 trang 201 0 0