Shared Objects in Flex
- Monday, March 23, 2009, 18:52
- ActionScript, Adobe Flex
- Add a comment
How nice it would be to welcome back or to recognize visitors who are revisiting your website or application. Adobe Flex provides ways to store objects in clients machine, and implementing does not compromise any issues on security of the client’s machine.
The Behaviour of shared objects is somewhat like a cookie. The class can be used to store data on the clients machine and retrive those objects in same session or in another session. The declaration part is as simple like Arrays , String or Date. You are also allowed to create multiple instance in one application and each instance is associated with a name to identify.Don’t worry readers, at the end i will provide you with an example.
private function visitingInfo():void
{
var dateInfo:SharedObject = SharedObject.getLocal(”userVisitedDate”);
trace(“SharedObject is ” + dateInfo.size + ” bytes”);
if(dateInfo.data.lastVisitedDate != null)
{
Alert.show(”Welcome back, you visited last on ” + dateInfo.data.lastVisitedDate);
}
dateInfo.data.lastVisitedDate = new Date();
dateInfo.flush();
}
Let me explain the code to you in brief. Initially we are creating a variable of return type sharedObject. The getLocal method tried to load a local shared Object with the name lastVisitedInfo. If there is no name, then a new object is created. Now in the coming line, we are checking whether it is is NULL and displaying an appropriate message. The final line is makes sure that your object is saved.
Popularity: 1% [?]
About the Author
Write a Comment
Gravatars are small images that can show your personality. You can get your gravatar for free today!