Using Shared Objects
Số trang: 18
Loại file: pdf
Dung lượng: 45.18 KB
Lượt xem: 11
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:
Đối tượng sử dụng chia sẻ tập tin SWF An có thể lưu dữ liệu (các biến cũng như mảng, XML, và các đối tượng dữ liệu khác) vào ổ cứng của người dùng bằng cách sử dụng chia sẻ các đối tượng, tương tự nhưng mạnh hơn các tập tin cookie được sử dụng bởi các trình duyệt Web. Bạn có thể sử dụng chia sẻ các đối tượng để lưu trữ thông tin được tạo ra bởi người sử dụng khi xem bộ phim tên...
Nội dung trích xuất từ tài liệu:
Using Shared Objects < Day Day Up >Using Shared ObjectsAn SWF file can save data (variables as well as array, XML, and other data objects) to ausers hard drive using shared objects—similar to but more powerful than the cookiesused by Web browsers. You can use shared objects to store information generated by theuser while viewing your movie (name, last frame visited, music preference, and so on).Shared objects can be used by movies played in a Web browser as well as those turnedinto stand-alone projectors.You can use shared objects with any of the following (for example): • XML.load • XML.sendAndLoad • LoadVars.load • LoadVars.sendAndLoad • LoadVariables • LoadVariablesNum • XMLSocket.connect • Importing a shared libraryThe following is an example of a script you might use to create a shared object:var myObject:SharedObject = SharedObject.getLocal(stuff_I_saved);If the shared object stuff_I_saved already exists on the users hard drive, its data is loadedinstantly into myObject. If stuff_I_saved does not yet exist, its created and stillreferenced by myObject. In the latter case, myObject would be empty—that is, it wouldcontain no data.NOTEIf used as just mentioned, the getLocal() method will create a shared object if none exists,or will retrieve data from an existing shared object.As you can see from the previous syntax, the shared objects name is actuallystuff_I_saved; however, in ActionScript you cant reference the shared object directlyusing that name. Therefore, a reference to the shared object is created using myObject.This means that whenever you reference myObject in a script, youre actually referencingthe shared object named stuff_I_saved—a tricky concept but essential to understandinghow ActionScript deals with shared objects.Data is saved to a shared object using the data property. Take a look at the followingexample:myObject.data.userName = userName_txt.text;This would save the userName variable (and its value, the text in the userName_txt textfield) in the shared object. You can save entire objects as well. For example, if youwanted to save an array contained by your project, you would use the following syntax:myObject.data.savedArray = nameOfArray;A single shared object can contain multiple bits of data simultaneously:myObject.data.savedArray = nameOfArrayObject;myObject.data.savedXML = nameOfXMLObject;myObject.data.userName = userName_txt.text;A particular piece of data can be erased from a shared object using null, as in thefollowing example:myObject.data.userName = null;If userName were a piece of data in the shared object, the preceding script would deleteit.You can delete an entire shared object by using the clear() method of the SharedObjectclass:myObject.clear();Extracting data from a shared object is similar to creating data in one:userName_txt.text = myObject.data.userName;In the userName_txt text field, the preceding script will display the value of userName inthe shared object. If this variable doesnt exist in the shared object, the value displayed inthe text field will be undefined.When the SWF session ends (that is, the movie is closed or exited), all the informationunder the data property of your shared object is automatically written to the shared objectfile, ready to be retrieved using the getLocal() method described earlier. You can force ashared object to be written and saved at any time by using the flush() method. Forexample:myObject.flush();This line of ActionScript forces your shared object and all the data it contains to besaved. Because myObject references the shared object named stuff_I_saved, this is theobject that will actually be saved.Flash stores all shared objects in a central location on the users hard drive—the exactlocation depends on where the movie resides that created the shared objects.On Windows XP, all shared objects are stored in the following general directory:Documents and Settings\Application DataMacromediaFlash Playerwhere is the name of the user who was logged on when the shared objectwas created.On a Mac, the location is as follows:System FolderPreferencesMacromediaFlash PlayerTIPDepending on the version of your operating system, the location of shared object filesmay vary somewhat. To locate shared object files on your machine, search for files withan .sol extension.These are both general paths—that is, when a movie creates a shared object, a newsubdirectory is created at one of the previously mentioned locations. For example, if youwere to view a movie at the following URL:http://www.electrotank.com/fun/games/MiniGolf.swfany shared object created by this movie would, by default, be saved at the following pathon a Windows machine:Documents and Settings\Application DataMacrome ...
Nội dung trích xuất từ tài liệu:
Using Shared Objects < Day Day Up >Using Shared ObjectsAn SWF file can save data (variables as well as array, XML, and other data objects) to ausers hard drive using shared objects—similar to but more powerful than the cookiesused by Web browsers. You can use shared objects to store information generated by theuser while viewing your movie (name, last frame visited, music preference, and so on).Shared objects can be used by movies played in a Web browser as well as those turnedinto stand-alone projectors.You can use shared objects with any of the following (for example): • XML.load • XML.sendAndLoad • LoadVars.load • LoadVars.sendAndLoad • LoadVariables • LoadVariablesNum • XMLSocket.connect • Importing a shared libraryThe following is an example of a script you might use to create a shared object:var myObject:SharedObject = SharedObject.getLocal(stuff_I_saved);If the shared object stuff_I_saved already exists on the users hard drive, its data is loadedinstantly into myObject. If stuff_I_saved does not yet exist, its created and stillreferenced by myObject. In the latter case, myObject would be empty—that is, it wouldcontain no data.NOTEIf used as just mentioned, the getLocal() method will create a shared object if none exists,or will retrieve data from an existing shared object.As you can see from the previous syntax, the shared objects name is actuallystuff_I_saved; however, in ActionScript you cant reference the shared object directlyusing that name. Therefore, a reference to the shared object is created using myObject.This means that whenever you reference myObject in a script, youre actually referencingthe shared object named stuff_I_saved—a tricky concept but essential to understandinghow ActionScript deals with shared objects.Data is saved to a shared object using the data property. Take a look at the followingexample:myObject.data.userName = userName_txt.text;This would save the userName variable (and its value, the text in the userName_txt textfield) in the shared object. You can save entire objects as well. For example, if youwanted to save an array contained by your project, you would use the following syntax:myObject.data.savedArray = nameOfArray;A single shared object can contain multiple bits of data simultaneously:myObject.data.savedArray = nameOfArrayObject;myObject.data.savedXML = nameOfXMLObject;myObject.data.userName = userName_txt.text;A particular piece of data can be erased from a shared object using null, as in thefollowing example:myObject.data.userName = null;If userName were a piece of data in the shared object, the preceding script would deleteit.You can delete an entire shared object by using the clear() method of the SharedObjectclass:myObject.clear();Extracting data from a shared object is similar to creating data in one:userName_txt.text = myObject.data.userName;In the userName_txt text field, the preceding script will display the value of userName inthe shared object. If this variable doesnt exist in the shared object, the value displayed inthe text field will be undefined.When the SWF session ends (that is, the movie is closed or exited), all the informationunder the data property of your shared object is automatically written to the shared objectfile, ready to be retrieved using the getLocal() method described earlier. You can force ashared object to be written and saved at any time by using the flush() method. Forexample:myObject.flush();This line of ActionScript forces your shared object and all the data it contains to besaved. Because myObject references the shared object named stuff_I_saved, this is theobject that will actually be saved.Flash stores all shared objects in a central location on the users hard drive—the exactlocation depends on where the movie resides that created the shared objects.On Windows XP, all shared objects are stored in the following general directory:Documents and Settings\Application DataMacromediaFlash Playerwhere is the name of the user who was logged on when the shared objectwas created.On a Mac, the location is as follows:System FolderPreferencesMacromediaFlash PlayerTIPDepending on the version of your operating system, the location of shared object filesmay vary somewhat. To locate shared object files on your machine, search for files withan .sol extension.These are both general paths—that is, when a movie creates a shared object, a newsubdirectory is created at one of the previously mentioned locations. For example, if youwere to view a movie at the following URL:http://www.electrotank.com/fun/games/MiniGolf.swfany shared object created by this movie would, by default, be saved at the following pathon a Windows machine:Documents and Settings\Application DataMacrome ...
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ó liên quan:
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 300 0 0 -
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 300 0 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 284 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 280 1 0 -
47 trang 250 4 0
-
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 247 0 0 -
80 trang 239 0 0
-
6 trang 231 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 227 0 0 -
122 trang 223 0 0