Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Where is the best place to declare a global variable  (Read 13990 times)
akmansoor
Newbie
*
Posts: 9


View Profile Email
« on: November 06, 2008, 08:02:23 »

I would like to declare a global variable where I can access it anywhere, this global variable reading data from an xml file. In puremvc where should I declare this global variable so that I can access it in mediators, command and proxy classes
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 on: November 06, 2008, 09:19:24 »

I would access the XML in a proxy and then access that proxy in your mediators, commands and other proxies.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
akmansoor
Newbie
*
Posts: 9


View Profile Email
« Reply #2 on: November 06, 2008, 11:42:56 »

Thanks,

each time the this proxy is retrieved is it going to load xml data? Do we need to make it singleton to avoid that, if so how to make proxy singleton


Mansoor
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #3 on: November 06, 2008, 12:06:06 »

You use the facade (singleton) to retrieve the proxy and place your variable on a public property of the Proxy. The facade is accessible from all Mediators, Commands and Proxies.

:
// Get your proxy
var myProxy:MyProxy = facade.retriveProxy(MyProxy.NAME) as MyProxy;

// access your variable.
myProxy.myGlobalVariable;

Proxies are "cached" within the facade and therefore do not have a short lifespan like a Command, unless you removeProxy();
Logged
akmansoor
Newbie
*
Posts: 9


View Profile Email
« Reply #4 on: November 06, 2008, 01:52:24 »

Thanks, really apreciate.

One more doubt on this.
Is it okey to declare global variable in ApplicationFacade
and  get the data through proxy and use facade to get the global variable.

ApplicationFacade
{
    public var myGlobalVariable;

   ApplicationFacade( ){
     var myProxy:MyProxy = facade.retriveProxy(MyProxy.NAME) as MyProxy;
     myGlobalVariable =  myProxy.retrieveGlobalVariables();
   }
}
[/color]
and then access the global variable using facade

Thanks,
Mansoor
Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #5 on: November 06, 2008, 02:03:37 »

Thanks, really apreciate.

One more doubt on this.
Is it okey to declare global variable in ApplicationFacade
and  get the data through proxy and use facade to get the global variable.

ApplicationFacade
{
    public var myGlobalVariable;

   ApplicationFacade( ){
     var myProxy:MyProxy = facade.retriveProxy(MyProxy.NAME) as MyProxy;
     myGlobalVariable =  myProxy.retrieveGlobalVariables();
   }
}
[/color]
and then access the global variable using facade

Thanks,
Mansoor

There is 100% no reason to do this as any mediator, command, or proxy can access the proxy by calling facade.retrieveProxy(MyProxy.NAME)

I recommend removing 'global variable' from your vocabulary in terms of PureMVC applications. ;)
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #6 on: November 06, 2008, 02:43:06 »


I recommend removing 'global variable' from your vocabulary in terms of PureMVC applications. ;)

Haha, I was think the same thing. Global variable is a dirty word, especially in AS3/OOP. ;)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: November 06, 2008, 04:37:52 »

Take a look at the Deployment Config utility. This is specifically for reading XML configuration and exposing it to your app.

-=Cliff>
Logged
Pages: [1]
Print