User specific login information is usually stored in session variables in any web application. However, Flex doesnt have anything called session variables in it. So how do we save this information across the whole application. Static classes come to the rescue here. This can also be achieved by use of shared objects and Singletons but I am going to focus on static classes for now.

A static class holds the information in it once declared and is very useful for such scenarios. Typically, after you are done with the username/password authentication in your Flex app, you would need to store the data in a static class to be able to access it from anywhere in your application.

Here is how we do it:-

package classes.UserInfo
{
public class UserInfo
{
private static var myUserName:String = "";
private static var myFullName:String = "";

public static function get UserFullName():String
{
return UserInfo.myFullName;
}
public static function set UserFullName(param:String):void
{
UserInfo.myFullName = param;
}
public static function get UserName():String
{
return UserInfo.myUsername;
}
public static function set UserName(param:String):void
{
UserInfo.myUserName = param;
}
public static function getInstanceMemento():Object
{
var o:Object = {
myUserName:            UserInfo.myUserName,
myFullName:            UserInfo.myFullName
};
return o;
}
public static function setInstanceMemento(param:Object):void
{
UserInfo.myUserName            = param.myUserName;
UserInfo.myFullName            = param.myFullName;
}
}
}

Once you have the class ready, you can use it to set the values. First , import the class you wrote in your mxml file.

import classes.UserInfo;

Then, after you are done with your authentication process, you can set the values :-

UserInfo.myUserName = "joebloggs";
UserInfo.myFullName = "Joe Bloggs";

and you can read this information anywhere in your application this way :-

UserInfo.myFullName

or you can use the getInstanceMemento() or setInstanceMemento() to do the above in one go!

Obviously, you can expand this class to include a lot of other informaion related to the user e.g. email, phone, fax etc and use it wherever required.