mike chambers | about

Global Variables within Flex Applications

The question of how to set up global variables in a Flex application came up on the Flex Components list recently, and as it comes up every so often, I figured I would blog one of the answers.

This is actually very easy. Just define a public variable within your main application class, like so:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			public var foo:String = "bar";
		]]>
	</mx:Script>
</mx:Application></pre>

You can then access that variable from anywhere within the Flex application via:

Application.application.foo

If you need to, you can still make the variable bindable.

Post and questions or suggestions in the comments.

twitter github flickr behance