Menu

[r11]: / trunk / SWFInvestigator / src / utils / ObjectEditor / ObjectRelay.as  Maximize  Restore  History

Download this file

127 lines (110 with data), 3.5 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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/****************************************************************************
* 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 utils.ObjectEditor
{
import flash.events.EventDispatcher;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import utils.ObjectEditor.ObjectRelayEvent;
/**
* Dispatched the status of the send
*
* @eventType StatusEvent.STATUS
*/
[Event(name="status", type="StatusEvent")]
/**
* Dispatched when an object has been received
*
* @eventType ObjectRelayEvent.OBJECT_RECEIVED
*/
[Event(name="objectReceived", type="ObjectRelayEvent")]
/**
* Dispatched when the Relay fails to set up the LC.connect
*
* @eventType ObjectRelayEvent.INIT_ERROR
*/
[Event(name="initError", type="ObjectRelayEvent")]
/**
* Dispatched when a remote editor wants the current object
*
* @eventType ObjectRelayEvent.SEND_REQUEST
*/
[Event(name="sendRequest", type="ObjectRelayEvent")]
public class ObjectRelay extends EventDispatcher
{
private var lConn:LocalConnection;
public var remoteConnection:String;
public var connected:Boolean = false;
public function ObjectRelay()
{
this.lConn = new LocalConnection();
this.lConn.client = this;
//One of the few times I actually mean this...
this.lConn.allowDomain("*");
this.lConn.addEventListener(StatusEvent.STATUS, onStatus);
}
/**
* @public
* Attempt to set up a LocalConnection listener on "objectEditor"
*/
public function initConnection():void {
try {
this.lConn.connect("objectEditor");
this.connected = true;
} catch (argError:ArgumentError) {
dispatchEvent(new ObjectRelayEvent(ObjectRelayEvent.INIT_ERROR));
}
}
/**
* @private
* Just pass the status event up the food chain
*
* @param e The StatusEvent.STATUS event.
*/
private function onStatus (e:StatusEvent):void {
dispatchEvent(e);
}
/**
* @public
* This is called via LocalConnection to request an object from the Object Editor
*
* @param theConnName Where the object should be sent back via LocalConnection
*/
public function sendObject(theConnName:String):void {
this.remoteConnection = theConnName;
dispatchEvent(new ObjectRelayEvent(ObjectRelayEvent.SEND_REQUEST));
}
/**
* @public
* Send an edited object back to the caller
*
* @param theObject The object to be sent back
*/
public function returnObject(theObject:*):void {
lConn.send(this.remoteConnection, "objectReceiver",theObject);
}
/**
* @public
* Called when an object needs to be edited in the Object Editor
*
* @param theObject The Object that will be edited.
*/
public function editObject(theObject:*):void {
var orEvent:ObjectRelayEvent = new ObjectRelayEvent(ObjectRelayEvent.OBJECT_RECEIVED, theObject);
dispatchEvent(orEvent);
}
/**
* @public
* Called to unregister the LocalConnection
*/
public function close():void {
this.lConn.close();
}
}
}
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.