<?xml version="1.0" encoding="utf-8"?>
<!-- 
 *
 *  LocalizedComponentSample
 *  Copyright (c) 2009 Robert Savage <www.savage7.com>
 *  Your reuse is governed by the Creative Commons Attribution 3.0 License
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 *
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                xmlns:myControls="com.savage7.controls.*"
                layout="absolute" 
                viewSourceURL="srcview/index.html" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#BDBDBD, #FFFDE3]">

    <mx:Metadata>
        [ResourceBundle("myResources")]
    </mx:Metadata>

    <mx:TitleWindow width="370" height="180" layout="absolute" horizontalCenter="0" verticalCenter="0" title="Localized Component Sample">
        <myControls:Label x="128.5" y="58" text="localized text goes here ..." resourceName="myLocalizedLabel" resourceBundle="myResources"/>
        <myControls:Button x="128" y="82" label="localized text goes here..." resourceName="myLocalizedButton" resourceBundle="myResources" cornerRadius="0" paddingLeft="5" paddingRight="5" paddingTop="5" paddingBottom="5"/>
        <mx:Label y="120" text="(hover mouse pointer over each control to see localized tool tip)" horizontalCenter="0" fontSize="9" fontStyle="italic" color="#949494"/>
        <mx:ApplicationControlBar x="0" y="0" cornerRadius="0" width="100%" dock="true" fillAlphas="[1.0, 1.0]" fillColors="[#E6E6E6, #CBCBCB]">
            <mx:Label text="Select Locale: " fontWeight="bold"/>
            <mx:ComboBox dataProvider="{['en_US','fr_FR','es_ES', 'ja_JP']}" change="selectLocale(event);"></mx:ComboBox>
        </mx:ApplicationControlBar>
        <mx:Label text="Localized Label:" fontWeight="bold" x="10" y="58"/>
        <mx:Label text="Localized Button:" fontWeight="bold" x="10" y="84"/>
    </mx:TitleWindow>
    
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            
            // --------------------------------------------------
            //  
            // NOTE:
            //
            // In the Flex Compiler settings under the Flex 
            // Builder project, we are including all three 
            // defined locales to be included in the compiled
            // SWF to be available at runtime.
            //
            //     Additional Compiler Arguments:
            //         -locale fr_FR en_US es_ES
            //
            // Also under the Flex Build path, the following
            // path is included:
            //          locale/{locale}
            //
            //
            // To localize the two controls on this page, all 
            // that is included is the 'resourceBundle' and 
            // 'resourceName' property on each component!
            //            
            // --------------------------------------------------

        
            /**
             * handles locale combo box change event when 
             * user selects a different locale to display
             */ 
            private function selectLocale(event:Event):void
            {
                // to change the active locale, all we need to
                // do is replace the locale chain in the 
                // resource manager with a new array where 
                // the first item in the array is the 
                // preferred/selected locale
                var localeChain:Array = new Array(1);
                localeChain[0] = event.target.selectedItem.toString();

                // replace locale chain with newly created locale array 
                resourceManager.localeChain = localeChain;
            }

        ]]>
    </mx:Script>
        
</mx:Application>