Menu

[r11]: / trunk / LCEnumerator / src / LCReceiver / LCReceiver.as  Maximize  Restore  History

Download this file

93 lines (85 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/****************************************************************************
* ADOBE SYSTEMS INCORPORATED
* Copyright 2012 Adobe Systems Incorporated and it’s licensors
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
* ****************************************************************************/
package LCReceiver
{
import flash.events.EventDispatcher;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
[Event(name="connectionReturned", type="LCReceiver.LCReceiverEvent")]
[Event(name="statusReturned", type="LCReceiver.LCReceiverEvent")]
/**
* A generic class for a LocalConnection so as not to expose the main SWF functions.
*/
public dynamic class LCReceiver extends EventDispatcher
{
private var conn:LocalConnection;
/**
* Constructor
* Sets up LocalConnection
*/
public function LCReceiver(allowDomain:String="")
{
this.conn = new LocalConnection;
if (allowDomain.length > 0) {
this.conn.allowDomain(allowDomain);
}
this.conn.client = this;
}
/**
* @private
* Propogate a success or failure message to the main SWF
*
* @param e A StatusEvent from the LocalConnection attempt to add a listener
*/
private function bubbleStatus(e:StatusEvent):void {
var sEvent:LCReceiverEvent = new LCReceiverEvent(LCReceiverEvent.STATUS_RETURNED);
switch (e.level) {
case "status":
sEvent.status = "LocalConnection.receive() succeeded";
break;
case "error":
sEvent.status = "LocalConnection.receive() failed";
break;
default :
sEvent.status = e.level + ": " + e.code;
}
dispatchEvent(sEvent);
}
/**
* This function adds the args received from the LocalConnection into LCReceiver event to be passed to the parent SWF
*
* @param args The array of arguments to send in the event handler
*/
public function bubbleArgs(args:Array):void {
var aEvent:LCReceiverEvent = new LCReceiverEvent(LCReceiverEvent.CONNECTION_RETURNED,args);
//aEvent.args = args;
dispatchEvent(aEvent);
}
/**
* Attempt to add a LocalConnection.connect using supplied name.
*
* @param connectionName The name of the function to listen on.
*/
public function connect(connectionName:String):void {
this.conn.addEventListener(StatusEvent.STATUS,bubbleStatus);
this.conn.connect(connectionName);
}
/**
* Close the LocalConnection
*/
public function close():void {
try {
this.conn.close();
} catch (e:ArgumentError) {
//Thrown if the connection was never opened.
//Don't really care.
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.