Session in Flex

You can Use the following class as a session in flex..
[Bindable]
private var session:Session = Session.getInstance();
How to insert data to session
session.setAttribute('username','sanka')
How to retrive data from session
var userName:String=session.getAttribute('username');
http://dl.dropbox.com/u/7375335/Session.as
package model
    import flash.utils.Dictionary;
    [Bindable]
     * @author Sanka Senavirathna
     *<p>
     *    Conforms to Singleton Design Pattern.
     *     </p>
     *    <p>
     *        Session.getInstance().getAttribute(key)
     *        Session.getInstance().setAttribute(key,value)
     * Code example for client
     [Bindable]
     private var session:Session = Session.getInstance();
     session.getAttribute('name')
     *    </p>
    public class Session
        private static var instance:Session = new Session();
        private var dic:Dictionary=new Dictionary(); // keep user session
        public function Session()
            if (instance != null) { throw new Error('Cannot create a new instance.  Must use Session.getInstance().') }
         * This Session is a Dictionary that keep key value pairs.Key can be object and value can be object.
         * [Bindable]
         * private var session:Session = Session.getInstance();
         * @langversion ActionScript 3.0
         * @playerversion Flash 8
         * @see getAttribute
         * @see setAttribute
         * @author Sanka Senavirathna
        public static function getInstance():Session
            return instance;
         * [Bindable]
         * private var session:Session = Session.getInstance();
         * Session.getInstance().setAttribute(key,value)
         * <p>example
         * session.setAttribute('username','sanka')
         *</p>
         * @langversion ActionScript 3.0
         * @playerversion Flash 8
         * @param key Describe key here.
         * @param value Describe value here.
         * @see getAttribute
         * @author Sanka Senavirathna
        public function setAttribute(key:*,value:*):void
            dic[key]=value;
         * [Bindable]
         * private var session:Session = Session.getInstance();
         * Session.getInstance().getAttribute(key)
         * <p>example
         * var userName:String=Session.getInstance().getAttribute('username');
         *</p>
         * @langversion ActionScript 3.0
         * @playerversion Flash 8
         * @param param1 Describe key here.
         * @see setAttribute
         * @author Sanka Senavirathna
        public function getAttribute(key:*):*
            return dic[key];

I think This will help you to keep your shaired data in single place.this will optimize your program by
reducing database hits,
reducing Server hits
Onece you retrive the data then put it into session (flex) and retrive it when you need..For example username in system.when user logged successfully
put the user object in to session and hide the login component.then pop-up your other component.But you can access the user data from session by using
var user:User=Session.getInstance().getAttribute('user'); something like that.
Hope this will help you.
enjoy
happy cording

Similar Messages

  • Regarding session in flex

    hi,
    My question is ,how i have set session in php and in flex. i could not know how to set session in flex and php.How to handle session in flex.
    Please provide me solution to solve the problem.
    Thanks and Regards,
    venkat.R

    Hi Venkat,
    You have to save PHPSESSID. for each request you made to server send this as URLVariable.
    I think this should work.
    let me know If it is helpfull.....
    Thanks,
    Vikram

  • Sessions in Flex

    Can anyone tell me how sessions work in Flex? From a browser perspective, I understand when a new session is created the ID is saved into a session cookie client-side and this ID is used to link the browser to the server-side session. But I can't find any cookies that relate to my Flex application (assuming it uses cookies).

    Session informatione is, basically, every variable you create and store in the Flex application.
    Sessions cookies are a work around for the stateless nature of HTML Pages.  Every HTML page exists in isolation andk nows nothing about any other HTML page or the history of the user viewing that page.  The server sets a cookie to match the request up a request with a server side session.
    In Flex, there is only one page request, so no need for cookies to keep track of sessions.  The complete app exists 'once' for each user; as opposed to the server side code which is shared across all users.
    That said, if you need sessions for your server side code; remote requests from Flex will include the cookie information set by the server; which will allow said requests to match your remote call to a server side session.
    Flex does not have access to read browser cookies, although it may be possible to do so using ExternalInterface and JavaScript.

  • Regarding maintaining session in flex

    Hello,
              I am developing a flex application which is using jsp for database connectivity. I am using HTTP request for connecting to jsp page and passing and retrieving parameters. Now I wanted to ask how can I maintain session in flex so that I can know which client has logged into the system and on the basis of that can assign privileges to the client. Is it possible in flex and how?Reply needed urgently.
    Thanks in advance.

    Hi a.bhavika,
    There is not specifically any session management in Flex as it runs everything on the client side if at all you want to mainatain you can maintain it on the server side. ...and I think for your case I dont think you need any session managemenet as at the time of login only you can identify which user has logged in to the syetem and based on the user logged in you can load all the previleges of that particular user in the Flex application.
    Check out the links below for your understanding...
    http://www.forta.com/blog/index.cfm/2006/9/24/flex-and-session-state-management
    http://www.assembla.com/wiki/show/romoz/Session_Management_in_Flex
    Thanks,
    Bhasker

  • How to create a login session in flex?

    Hi there,
    I have a flex application with two states. One is a "login" state which is a screen with username and password. The other state is "loggedIn" state which is a screen with a small application. As soon as the user credentials are checked from the back end, based on it's success, I'm changing the state to "loggedIn", else there is a message to the user about login failure in "login" state itself.
    My problem is if I'm in "loggedIn" state and if I hit refresh button of the webpage(F5), it goes back to the login screen i.e., it just restarts the application..
    How can I control this? Is there something like login session which can do the trick?
    Appreciate your help...
    -Deepak

    Flex code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="getSession.send()">
        <mx:Script>
            <![CDATA[
                import mx.rpc.events.ResultEvent;
                public function getSessionStuff(evt:ResultEvent):void
                    saveInfo.text = evt.result.info;
            ]]>
        </mx:Script>
        <mx:HTTPService id="startSession" showBusyCursor="true" method="POST" url="http://localhost/startSession.php">
            <mx:request xmlns="">
                <stuffToSave>
                    {saveInfo.text}   
                </stuffToSave>
            </mx:request>
        </mx:HTTPService>
        <mx:HTTPService id="getSession" result="getSessionStuff(event)" showBusyCursor="true" method="POST" url="http://localhost/getSession.php"/>
        <mx:Button x="602" y="323" label="Start Session" enabled="{saveInfo.text != ''}" click="startSession.send()"/>
        <mx:TextInput id="saveInfo" x="563" y="293"/>
    </mx:Application>
    setSession.php code;
    <?php
        session_start();
        $_SESSION['loggedIn'] = $_POST["stuffToSave"];
    ?>
    getSession.php code;
    <?php
        session_start();
        if($_SESSION['loggedIn'])
            echo "<info>".$_SESSION['loggedIn']."</info>";
        else
            echo "<info>nothing has been saved</info>";
    ?>
    ta daa

  • HTTP Session in Flex 2

    Hi,
    I want to know how to work with the HTTP Session object in
    Flex 2?
    Piece of code is really appreciable.
    Thanks,
    -Sameer

    Check out the example from the docs:
    http://livedocs.macromedia.com/flex/2/langref/mx/rpc/http/mxml/HTTPService.html#includeExa mplesSummary
    That should get you started...

  • Implementing Session in flex (Store an object in Session)

    Hi All,
       Is it possible to store an array collection in session ? How can this be implemented ?
    Thanks

    Have the password visible??? Why??? All you have to do is to capture the password that the user typed in and pass it as a variable to the connection string.
    Say, if you are using the JDBC:ODBC bridge, it will be something like this:
    Connection con = DriverManager.getConnection(
    url, login, password);
    //where url, login, and password are all variables.
    Hope this helps.

  • Regarding flex session

    hi,
    My question is ,using username and password i was logged in.But how i have to set userid into session in flex. i am using backend server PHP.
    please find me the solution to solve the problem.
    Thanks and Regards,
    venkat.R

    Hi a.bhavika,
    There is not specifically any session management in Flex as it runs everything on the client side if at all you want to mainatain you can maintain it on the server side. ...and I think for your case I dont think you need any session managemenet as at the time of login only you can identify which user has logged in to the syetem and based on the user logged in you can load all the previleges of that particular user in the Flex application.
    Check out the links below for your understanding...
    http://www.forta.com/blog/index.cfm/2006/9/24/flex-and-session-state-management
    http://www.assembla.com/wiki/show/romoz/Session_Management_in_Flex
    Thanks,
    Bhasker

  • Session Implementation in flex application

    Hi ,
    I m getting problem in how to implement session in flex
    application.
    Thanks in advance

    I'm not using Flex, but the following preserves session in Flash:
    var url = "http://" + WebServerIPAddress + "/" + ApplicationName + "?data=" + datavalue;
    var cmd:String = "window.open('" + url + "','win','height=768,width=1024,toolbar=no,scrollbars=yes');";
    var request:URLRequest = new URLRequest("javascript:" + cmd + " void(0);");
    navigateToURL(request, "_self");

  • Flex Session & login logout

    I have a web application in flex with back end as LCDS. I want to execute a function in server when the client logs out/close the browser.
       How can I implement this ( calling a severside function while user close the browser without properly logging out)?
    Can anybody help me?

    thank you for your advice yogi, but I would be more understanding if tried in the form of training / tutorials, can you tell the link that discusses login / logout session using flex and java
    thanks

  • Issue with sticky sessions

    My application has the following architecture:
    1.) a load balanced Flex frontend with sticky sessions which queries
    2.) a load balanced REST service also with sticky sessions
    The flex frontend queries the service using a Flex HTTPService object.  However, although sticky sessions are enabled on both the flex frontend and
    rest service, we are seeing queries go to different instances. For example
    user will request Flex App1 which will then call RestService1
    then user will request Flex App1 again which will call RestService2(instead of RestService1).
    Has anyone seen this issue before in a load balanced environment?  I need this to work because the REST service does not have a distributed cache, so subsequent requests must hit the same box to use the cache.
    thanks

    NW6 SP5 needs nw6nss5c in order for NSS to work properly; once applied
    then do
    nss /poolrebuild /purge
    on all pools. Make sure you have tested backups first, just in case.
    Also Load Monitor - Server Parameters - NCP. Set Level 2 OpLocks Enabled
    = Off, and Client File Caching Enabled = Off.
    What lan driver, date and version, on the server?
    Andrew C Taubman
    Novell Support Forums Volunteer SysOp
    http://support.novell.com/forums
    (Sorry, support is not provided via e-mail)
    Opinions expressed above are not
    necessarily those of Novell Inc.

  • Remote debugging Flex

    Hi,
    I use a windows XP sp3
    I have a Flex application which is embedded in JSP page and deployed in a weblogic server in a different unix machine.
    The JSP maintains session
    The Flex app uses remote objects to communciate with the Weblogic server which requires session related parameters. All these parameters are maintained in JSP
    I cudn't debug my Flex App which I execute locally..
    In the services-config.xml, I configured it to point the remote server but it is not working because of the session parameters
    I used a Httpservice to get the session parameters which is also not working.
    is there any way to debug a SWF which is embedded in a JSP and which also uses values from the session object to access remote objects.
    Thanks  & Regards
    mxvx

    For this type of Flex-specific query, you might get a better
    response at the Flex forum:
    http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid=60&catid=585&entercat= y

  • Flashbuilder and Cold Fusion  (using application/session variables)

    I would like to know if anybody uses Flashbuilder with Cold Fusion?
    Since Cold Fusion has lots of different scopes of variables (application, session, client, form, url, etc...) how do you manage this in Flex/Flashbuilder?
    Are there forums or groups specifically for using Flex3/Flashbuilder with backend server side technologies such as Cold Fusion?.
    The only server side technology that I have interest in is Cold Fusion.  I've seen basic tutorials and videos using Cold Fusion CFC's and data binding with Flex.  I haven't seen or heard anything using a Cold Fusion application, session, or client variable in Flex.
    Hopefully some of you have some experience on this topic.
    Thanks

    hey popster,
    i too had this question some time ago. my entire app was built on CF with HTML before i started integrating Flex 3 with it. i found that i needed to create cookie variables for all my session variables i was using in order to maintain and remember who the user was in my CFC calls. i also found that after i compiled a flex app, i changed the .html to .cfm (the file that loads the compiled SWF file). by doing this i was able to pass CF session variables into the flex app and you can refer to these anywhere in Flex by using Application.application.parameters.{variable name here} 
    add the CF variable in the FlashVars line to pass it into Flex (see the last line of code). this will create a variable (in my case i'm passing session.employeenumber). then in your flex app you can reference it by using Application.application.parameters.emplid:
    AC_FL_RunContent(
       "src", "Request",
       "width", "100%",
       "height", "87%",
       "align", "middle",
       "id", "Request",
       "quality", "high",
       "bgcolor", "#869ca7",
       "name", "Request",
       "allowScriptAccess","sameDomain",
       "type", "application/x-shockwave-flash",
       "pluginspage", "http://www.adobe.com/go/getflashplayer",
       "wmode","transparent",
       "FlashVars","emplid=<cfoutput>#session.employeenumber#</cfoutput"
    A little trick I learned (does Adobe really expect us to re-engineer how our apps have been working by no longer using sessions for Flex?). Then in your CFCs if you also create cookies for every session variable you can maintain the variables based on user login. HOPE THIS HELPS!
    -Matt

  • Invalidate session in BlazeDS

    Hi!
    I need to integrate BlazeDS security with an external security mechanism so I have implemented custom authentication as described in http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=services_security_1 .html. Now I need to invalidate user authentication on server upon certain circunstances. When this happens, I invalidate Session contained in Request parameter of invoke method of TomcatValve. This seems to work but I get a nasty "Duplicated Http Session" in Flex client telling that cookies where removed in server. Is there any clear way to invalidate current user login from BlazeDS?
    I've also tried invalidating FlexSession but then Flex clients hangs.
    Thank you very much.
    Daniel.

    Ummm - isn't that exactly what a session timeout specifies?
    ie how long should it stick around before it "expires" and should be invalidated?
    You don't need to call session.invalidate() - it will do that all by itself.

  • Login security in flex with Java

    Hi ,
    I am looking for login secruity with session in flex.
    Thanks,
    Alok

    If you want to use Java as the back end, you have BlazeDS and
    LiveCycle Data services to make your programming simpler. BlazeDS
    and LCDS will allow you to invoke the Java classes from the Flex
    application. For more details on BlazeDS and LCDS visit the URLs
    below.
    http://www.adobe.com/products/livecycle/dataservices/
    http://opensource.adobe.com/wiki/display/blazeds/BlazeDS
    Hope this helps.

Maybe you are looking for

  • Error with Oracle Workflow Manager

    Hi Oracle workflow has just been installed on my first middle tier from the Content management SDK 9.0.4 CD. ( I have also an old working installation on the second middle tier, pointing to an old database 9.2.0.2) When I click on the Oracle Workflow

  • What is the screen lock default code for iPod nano 5th gen?

    What is the screen lock default code for iPod nano 5th gen?

  • Aperture's internal Color Space?

    Does anyone have any information about Aperture's internal color space?

  • My ipod 4g wont charge

    my ipod suddenly stopped charging. it was charging well the night before and like 5 mins later it stopped charging i reset it and everything. please help

  • Art deforming when scaling

    Has anyone noticed their artwork becomming deformed after scaling or moving it? I attached a screenshot of a piece of clipart that I scaled down twice with the original showing on top. You can see in the art in the middle position that it's been chan