« Back To Articles List

Is there any static variable type available in server side?

Graeme Bull - Feb 04, 2006

Question:
Is there any static variable type available in server side ? so that I can change that variable globally.

Answer:
Yes. With FMS2 you can actually set variables in the application.xml file. Now if you set these variables in this file and put the application.xml file in the application directory, the variables you set will be available to instances of that application only. Not any others.

If you don't put an application.xml file in the application directory of the application that you are running, then FMS will default to the level higher which would be the conf directory for the virtualhost you are running and look in there. That's where we are going to set our variable.

So, open up the application.xml file in some text editor and jump down to the tag
<code><JSEngine></code>

In there we are going to add a couple of new tags:
<code><ApplicationObject></code>

Inside there:
<code><config></code>

And in there we are going to add a super user tag and put my name in it:
<b>superUser</b>

<i>Graeme Bull</i>

So it looks like this:
<code>
<JSEngine>

     <ApplicationObject>

          <config>

               <superUser>Graeme Bull</superUser>

          </config>

     </ApplicationObject>

</JSEngine>
</code>

Now, save the file, restart the server and make a main.asc file because we are now going to trace this value out:

application.onAppStart = function(){
     trace("The Super User is: " + application.config.superUser);
}

Now when you start up the application you should see the following trace:

<b>The Super User is: Graeme Bull</b>

That's it :)