SWF파일끼리 통신하는 예제입니다. 

 

* 보내는쪽

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

<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"

                   minWidth="955" minHeight="600"

                   creationComplete="initConn()"

                   >

    

     <fx:Script>

           <![CDATA[

                import flash.net.LocalConnection;

               

                private var conn:LocalConnection;

               

                private function initConn():void

                {  

                     btnSend.addEventListener(MouseEvent.CLICK, sendMessage);  

                     conn = new LocalConnection();      

                     conn.addEventListener(StatusEvent.STATUS, onStatus);   

                } 

               

                private function sendMessage(event:MouseEvent):void

                {    

                     conn.send("taskConnection", "localconnectionHandler", inputTask.text);      

                }       

               

                private function onStatus(event:StatusEvent):void

                {     

                     switch (event.level)

                     {          

                           case "status":             

                                labelStatus.text = "LocalConnection.send() succeeded"; 

                                break;             

                           case "error":           

                                labelStatus.text = "LocalConnection.send() failed";                

                                break;    

                     }   

                }

           ]]>

     </fx:Script>

    

     <mx:Panel horizontalCenter="0" verticalCenter="0">      

           <mx:Form width="100%" height="100%" horizontalCenter="0" verticalCenter="0"> 

                <mx:FormItem label="Enter Task">              

                     <mx:TextInput id="inputTask"/>           

                </mx:FormItem>         

                <mx:FormItem label="Send Task ">        

                     <mx:Button id="btnSend" label="Send"/>  

                </mx:FormItem>           

                <mx:ControlBar> 

                     <mx:Label id="labelStatus" text=""/>      

                </mx:ControlBar>       

           </mx:Form>  

     </mx:Panel>

</s:Application>

 

* 받는쪽

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

<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"

                   minWidth="955"

                   minHeight="600"

                   creationComplete="InitConn()"

                   >    

     <fx:Script>

           <![CDATA[

                import flash.net.LocalConnection;      

               

                private var conn:LocalConnection;   

               

                private function InitConn():void

                {  

                     conn = new LocalConnection();   

                     conn.client = this;             

                     try {                

                           conn.connect("taskConnection");    

                     } catch (error:ArgumentError) {       

                           trace("Can't connect.");       

                     }         

                }         

               

                public function localconnectionHandler(msg:String):void

                {   

                     textareaTasks.text= textareaTasks.text + msg + "\n";   

                }           

               

                private function clearTasks(event:MouseEvent):void

                {              

                     textareaTasks.text="";      

                }

           ]]>

     </fx:Script>

    

     <mx:Panel  horizontalCenter="0"       

                   verticalCenter="0.5"    

                   verticalGap="15"     

                   paddingLeft="20"

                   paddingRight="20"

                   paddingBottom="20"

                   paddingTop="20"    

                   height="300"

                   width="500"

                   >      

           <mx:Label text="Your tasks are..."/>   

           <mx:TextArea id="textareaTasks"        

                            top="20" left="20" right="20" bottom="20"  

                            width="100%" height="100%"/>  

           <mx:HBox>         

                <mx:Button id="btnClearTasks" click="clearTasks(event)" label="Clear Tasks"/>  

           </mx:HBox>  

     </mx:Panel>

</s:Application>


저작자 표시 비영리
신고
YOUR COMMENT IS THE CRITICAL SUCCESS FACTOR FOR THE QUALITY OF BLOG POST


티스토리 툴바