Photoshop Tutorials, Flash Tutorials, 3Ds Studio Max Tutorials, Web Design Tutorials |
Home | Submit Tutorial | Top Sites | Free Templates (NEW) | Website templates | Privacy Policy | Link Exchange | Contact Us |
|
Welcome To ProDesignHost.com Flash Tutorials Area - Using Local Shared Objects in Flash MX
Before Flash MX, it was pretty tricky to "remeber" the data in a Flash
movie - it could be done with a standard browser cookie, which was hard
to implement for someone with intermediate Flash skills, using a 3rd
party script such as PHP or ASP or (in offline Flash applications) with
the undocumented fscommand "save". Flash MX's Shared objects allow to
store and retrieve the information within a Flash movie easily. Lets
see how it works.
What is a local shared object ? Flash MX Shared objects is a new feature allow you to store information at the user's machine the same way as cookies would and retreive it at a later time. Shared objects could be used to remember the user's name, the number of the level he last played in a game, his highscore or anything else you can imagine. Shared objects are stored in .sol files located in the Flash player directory of the user's profile : "C:/Documents and Settings/Administrator/Application Data/Macromedia/Flash Player", and have their own format Here is a working example of a movie using the Shared Object. Type in your name and age and click on "Save". Then, refresh this page to let Flash read and display the stored data: Creating a shared object First, we have to create a local shared object within a Flash movie. To do so, just put this line of code in the first frame of your movie:
Now we have created an Object named "local_data" which is associated with a shared object on the local hard-drive named user_data. Note that in the feature, this data can be read from other movies from the same domain that created the Shared Object. Writing data Lets store something in our fresh created Shared Object. Lets say, we want to store the user's name and his age in it. To do so, use this:
Note that this code must be in the same level where you have created the Shared Object. The flush () command is optional, it is used to write the information to disk immediately. If you don't use this command, Flash MX writes the shared object to a file when the SWF movie is closed or when the shared object is garbage-collected because it no longer has any references to it. Reading data To retrieve data from a saved Shared Object, just use the following syntax:
Don't forget that you still have to create the local_data shared object first. Now, the user's name is stored in a variable called "stored_user_name" and the user's age in the variable "stored_user_age"and you can use it anywhere in your movie. You can store more information in one Shared Object file in the same way. Similar to the way how we have saved simple text variables you can store whole arrays and other objects. Important notices There are some important things to remember when using the local Shared Objects in your movies:
Author: Phillip Kostin
|
|
Premium Partners | |||||
|
|||||
Free website templates and paid web templates are great tools to make your websites look perfect! You will save time and money with our flash templates and free website templates
Our visitors are satisfied with the quality of our free and paid website templates! Please visit our free website templates and paid website templates sections. We offer free web templates, free web layouts, free web page templates and other stuff for free download. All templates come with the html and external css file so you may easily edit HTML with your favorite HTML editor. Feel free to download our free web templates for your personal websites. Terms of use depend upon the website template vendor. |
Home | Submit Tutorial | Top Sites | Free Templates | Website templates | Privacy Policy | Contact Us |