In one of my AIR based chat applications, which is used internally, I need to get the user name of the user currently logged in to the application.
In the application, our requirement is to make a chat application to be used internally. Since each user requires a unique login name, we'll use the company user name for each individual as those are unique for each internal user.
In the application, we use the File class to get the user's information, using this class we manipulate the userDirectory nativepath; using that object it's easy to get the user name out of the system.
//////////////////////////////////////////// Application /////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="onCreationComplete(event)">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
private function onCreationComplete(event:FlexEvent):void
{
Alert.show( getSystemUser() );
}
private function getSystemUser():String
{
var userDir:String = File.userDirectory.nativePath;
var userName:String = userDir.substr(userDir.lastIndexOf(File.separator) + 1);
return userName;
}
]]>
</mx:Script>
</mx:WindowedApplication>
+