<?xml version="1.0" encoding="utf-8"?>
<!--

    Example of Flex talking to Flash
    Jesse R. Warden
    jesterxl@jessewarden.com
    http://www.jessewarden.com
    
-->
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute" 
    currentState="main_state"
    creationComplete="init()">
    
    
    <mx:Script>
        <![CDATA[
        
            public static const FLASH_LC_IN_NAME:String                = "_JXLFlashProxy_IN";
            public static const FLASH_LC_OUT_NAME:String            = "_JXLFlashProxy_OUT";
    
            protected var in_lc:LocalConnection;
            protected var out_lc:LocalConnection;
            
            protected function init():void
            {
                // Flash talks to me
                in_lc = new LocalConnection();
                in_lc.client = this;
                in_lc.connect(FLASH_LC_OUT_NAME);
                
                // I talk to Flash
                out_lc = new LocalConnection();
                
                proxy_ldr.load("proxy.swf");
            }
            
            protected function onPlayVideo():void
            {
                out_lc.send(FLASH_LC_IN_NAME, "playVideo", "assets/flash/Proxy/video_player.swf");
            }
            
            protected function onStopVideo():void
            {
                out_lc.send(FLASH_LC_IN_NAME, "stopVideoPlayer");
            }
            
            protected function onProxyLoaded():void
            {
                currentState = "ready_state";
            }
            
            // From Flash
            public function onPlayVideoResult(result:Boolean, error:String=""):void
            {
                
            }
            
            public function onVideoPlayerLoaded():void
            {
                playVideo_pb.enabled = false;
                stopVideo_pb.enabled = true;
            }
            
            public function onStopVideoPlayerResult(result:Boolean, error:String=""):void
            {
                if(result == true)
                {
                    playVideo_pb.enabled = true;
                    stopVideo_pb.enabled = false;
                }
            }
            
            
        ]]>
    </mx:Script>
    
    <mx:Style source="/assets/styles/default.css" />
    
    <mx:states>
        <mx:State name="main_state">
            <mx:AddChild position="lastChild">
                <mx:Canvas x="0" y="0" width="100%" height="100%">
                    <mx:Button x="10" y="10" label="Play Video" click="onPlayVideo()" enabled="false" id="playVideo_pb"/>
                    <mx:Button x="101" y="10" label="Stop Video" click="onStopVideo()" enabled="false" id="stopVideo_pb"/>
                    <mx:Canvas x="10" y="40" width="370" height="290" backgroundColor="#000737" cornerRadius="10" borderStyle="solid">
                        <mx:SWFLoader 
                            x="4" y="4" 
                            width="360" height="280" 
                            id="proxy_ldr"
                            maintainAspectRatio="true"
                            scaleContent="false"
                            complete="onProxyLoaded()"/>
                    </mx:Canvas>
                    <mx:Label x="194" y="12" text="Loading Proxy, please wait..." id="label1"/>
                </mx:Canvas>
            </mx:AddChild>
        </mx:State>
        <mx:State name="ready_state" basedOn="main_state">
            <mx:SetProperty target="{playVideo_pb}" name="enabled" value="true"/>
            <mx:RemoveChild target="{label1}"/>
        </mx:State>
    </mx:states>
    
</mx:Application>