![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
Hi All,
My app have a login page, after validate my login I want to stored the userid in a global variable so I can use it alone all the app in flex. Can I do global variables? How can I do this? In the pass I was able to do using session variables. thanks JFB |
| Sponsored Links |
|
|||
|
Global variables as in AS2 do not exist in AS3.
Global variables are usually a bad idea from a design point of view. However the easiest way to do what you want is to define your username or authorization variable on the main application object. Then anywhere in your code you can access it via: Application.application.yourAuthorizationVariable Be sure to include where appropriate: import mx.core.Application |
|
|||
|
[I agree mostly with what gsb has posted. However I personally don?t like to
have any object accessing a variable somewhere in the application. ] I don?t see why you would need to have a global variable in a Flex application. If you need to simply store the user id, you should do this in your model (that?s if you have one). If there is no model in your application then I would create a singleton class perhaps called ?SessionModel?. And in this class you can have a getter/setter to store the user?s id. Then this can be accessed by any object in your application. However, as always you shouldn?t exploit this design pattern (Singleton) freely. Descendants of a parent object shouldn?t be tapping into a singleton. They should be accessing their parent object for that info. At least that is a simple rule of mine and others. Or are you talking about shared objects? Which retains data on the user?s machine when the user returns to the application after it has been terminated? |
|
|||
|
To simply put it, a disadvantage of assigning a variable in the application
object is that it will be terminated when the application terminates. The advantage of having a shared object, is that a variable can be retrieved so that the user doesn?t have to reenter their id (Assuming that the user hasn?t cleared their browser cache). If you do choose to use shared objects, keep in mind, then anyone using that browser can access the account of the user?s shared object. //Shared Objects in Help docs http://livedocs.adobe.com/flex/3/htm...nt=lsos_1.html |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise