<?xml version="1.0" encoding="utf-8"?>
<!-- 
Copyright (c) 2010 http://www.immanuelnoel.com

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->

<!--
The Component displays the text retreived from a local XML file, on a PopUp, at the click of a button
-->

<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" backgroundAlpha="0" 
                   creationComplete="bordercontainer1_creationCompleteHandler(event)">
    <s:layout>
        <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/>
    </s:layout>

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import mx.managers.PopUpManager;
            
            private var xmlData:String = "";
            var urlLoader:URLLoader;
            
            /** Method called on the 'creationComplete' event of the component
             * 
             *     Reading the XML file
            */
            protected function bordercontainer1_creationCompleteHandler(event:FlexEvent):void
            {
                var url:URLRequest = new URLRequest("/Example2_Files/Example2_Data.xml");
                urlLoader = new URLLoader(url);
                urlLoader.addEventListener(Event.COMPLETE, function(){
                    xmlData = String(XML(urlLoader.data));
                });
            }
            
            /** Displaying a PopUp, and updating the label in the PopUp 
             *     with the value fetched from the XML file
             */
            protected function button1_clickHandler(event:MouseEvent):void
            {
                var xml:XMLDocument = new XMLDocument(xmlData);
                xml.ignoreWhite = true;
                
                var popup:Example2_PopUp = PopUpManager.createPopUp(this, Example2_PopUp, true) as Example2_PopUp;
                PopUpManager.centerPopUp(popup);
                popup.lDisplay.text = String(xml.childNodes[0].childNodes[1].childNodes[0].nodeValue);
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Label text="Demostrates reading data from a local XML file," color="#FFFFFF" fontFamily="Verdana" fontSize="14"/>
    <s:Label text="and displays a PopUp" color="#FFFFFF" fontFamily="Verdana" fontSize="14"/>
    <s:Button label="Click Me !" click="button1_clickHandler(event)"/>
</s:BorderContainer>