In Flex4.5, a Bindable variable defined in main Application MXML cannot be directly used to binding data in the custom components which are created in different packages. The following code shows how to let all the other components access a global variable.
In the Application MXML, define a bindable variable
In the Application MXML, define a bindable variable
- <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx">
- <fx:Script>
- <![CDATA[
- [Bindable]
- public var globalVariable:String = "Global Variable";
- ]]>
- </fx:Script>
- </s:Application>
- <?xml version="1.0" encoding="utf-8"?>
- <s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/mx">
- <fx:Script>
- <![CDATA[
- import mx.core.FlexGlobals;
- [Bindable]
- private var application:Object = FlexGlobals.topLevelApplication;
- ]]>
- </fx:Script>
- <s:TextInput text="{application.globalVariable}"/>
- </s:Panel>
No comments:
Post a Comment