5

Global Variables within Flex Applications

 3 years ago
source link: http://www.mikechambers.com/blog/2007/02/05/global-variables-within-flex-applications/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Global Variables within Flex Applications

Monday, February 5, 2007

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK