February 04, 2006

Ask an FMS Guru #2: Is there any static variable type available in server side?

I thought this would be a great second question for the infamous FMS Guru :)

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
<JSEngine>

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

Inside there:
<config>

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

Graeme Bull

So it looks like this:
<JSEngine> <ApplicationObject> <config> <superUser>Graeme Bull</superUser> </config> </ApplicationObject> </JSEngine>

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:

The Super User is: Graeme Bull

That's it :)

Posted by Graeme at February 4, 2006 02:21 AM
 



Comments