wvxvw
10-16-2008, 02:30 PM
Hi.
I have tried to write the simple AIR app that would log my AS2 SWF that I need to load from localhos. I'm guessing the problem is in security for LocalConnection, but don't know how to permit AS2 SWF to call LC in the AIR app.
Here's the code:
(AIR)
<?xml version="1.0"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="handleAppComplete(event)">
<mx:Script>
<![CDATA[
import com.aditall.log.Logger;
import flash.events.Event;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import mx.core.WindowedApplication;
public var loggerLC:Logger;
//public var testLC:LocalConnection;
[Bindable]
public var loggerMessage:String;
public function handleAppComplete(evt:Event):void
{
logArea.width = (evt.target as WindowedApplication).width - 80;
logArea.height = (evt.target as WindowedApplication).height - 80;
//testLC = new LocalConnection();
//testLC.addEventListener(StatusEvent.STATUS, handleStatus);
loggerLC = new Logger();
loggerLC.addEventListener(Logger.LOG_RECEIVED, handleLogUpdate);
loggerLC.log(loggerLC.domain);
//testLC.send("aditallmixer", "log", "Hi!");
}
private function handleStatus(evt:StatusEvent):void
{
trace(evt.level);
}
private function handleLogUpdate(evt:Event):void
{
loggerMessage = loggerLC.logMessage;
}
]]>
</mx:Script>
<mx:TextArea text="{loggerMessage}" id="logArea" />
</mx:WindowedApplication>
If you uncomment the lines connected to testLC you will see that logger actually works, it just cannot communicate to the SWF on localhost
package com.aditall.log
{
import flash.events.Event;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
[Event("logReceived")]
/**
* Logger class.
* @author wvxvw
*/
public class Logger extends LocalConnection
{
public static const LOG_RECEIVED:String = "logReceived";
private static const MIXER_LC_NAME:String = "aditallmixer";
private var _logMessage:String = "Connecting...";
public function Logger()
{
super();
client = this;
allowDomain("localhost", "http://localhost/local/MIXER/mixer_build_mtasc.swf");
allowInsecureDomain("localhost", "http://localhost/local/MIXER/mixer_build_mtasc.swf");
connect(MIXER_LC_NAME);
}
public function log(logStr:String):void { logMessage = logStr; }
[Bindable("logReceived")]
public function get logMessage():String { return _logMessage; }
public function set logMessage(s:String):void
{
trace("called "+s);
_logMessage = s;
dispatchEvent(new Event(LOG_RECEIVED));
}
}
}
(AS2)
....
if (!_lc)
{
_lc = new LocalConnection();
_lc.send(_lcName, LOG, _settings);
_lc.onStatus = Delegate.create(Tracer, onLCStatusDelegate);
_lc.allowDomain("app#com.aditall.log.logger");
}
....
_lc.send(_lcName, LOG, sender + JS_SEPARATOR + message);
....
static private function onLCStatusDelegate(infoObject:Object):Void
{
getURL(JS_TRACER + "[onStatus]" + JS_SEPARATOR + infoObject.level + " domain " + _lc.domain() + JS_CLOSE);
}
....
Here I'm trying to send a message to the LC in AIR logger, and if the attemt fails I print it into FireBug console... unfortunately it fails...
Any insights?
I have tried to write the simple AIR app that would log my AS2 SWF that I need to load from localhos. I'm guessing the problem is in security for LocalConnection, but don't know how to permit AS2 SWF to call LC in the AIR app.
Here's the code:
(AIR)
<?xml version="1.0"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
applicationComplete="handleAppComplete(event)">
<mx:Script>
<![CDATA[
import com.aditall.log.Logger;
import flash.events.Event;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
import mx.core.WindowedApplication;
public var loggerLC:Logger;
//public var testLC:LocalConnection;
[Bindable]
public var loggerMessage:String;
public function handleAppComplete(evt:Event):void
{
logArea.width = (evt.target as WindowedApplication).width - 80;
logArea.height = (evt.target as WindowedApplication).height - 80;
//testLC = new LocalConnection();
//testLC.addEventListener(StatusEvent.STATUS, handleStatus);
loggerLC = new Logger();
loggerLC.addEventListener(Logger.LOG_RECEIVED, handleLogUpdate);
loggerLC.log(loggerLC.domain);
//testLC.send("aditallmixer", "log", "Hi!");
}
private function handleStatus(evt:StatusEvent):void
{
trace(evt.level);
}
private function handleLogUpdate(evt:Event):void
{
loggerMessage = loggerLC.logMessage;
}
]]>
</mx:Script>
<mx:TextArea text="{loggerMessage}" id="logArea" />
</mx:WindowedApplication>
If you uncomment the lines connected to testLC you will see that logger actually works, it just cannot communicate to the SWF on localhost
package com.aditall.log
{
import flash.events.Event;
import flash.events.StatusEvent;
import flash.net.LocalConnection;
[Event("logReceived")]
/**
* Logger class.
* @author wvxvw
*/
public class Logger extends LocalConnection
{
public static const LOG_RECEIVED:String = "logReceived";
private static const MIXER_LC_NAME:String = "aditallmixer";
private var _logMessage:String = "Connecting...";
public function Logger()
{
super();
client = this;
allowDomain("localhost", "http://localhost/local/MIXER/mixer_build_mtasc.swf");
allowInsecureDomain("localhost", "http://localhost/local/MIXER/mixer_build_mtasc.swf");
connect(MIXER_LC_NAME);
}
public function log(logStr:String):void { logMessage = logStr; }
[Bindable("logReceived")]
public function get logMessage():String { return _logMessage; }
public function set logMessage(s:String):void
{
trace("called "+s);
_logMessage = s;
dispatchEvent(new Event(LOG_RECEIVED));
}
}
}
(AS2)
....
if (!_lc)
{
_lc = new LocalConnection();
_lc.send(_lcName, LOG, _settings);
_lc.onStatus = Delegate.create(Tracer, onLCStatusDelegate);
_lc.allowDomain("app#com.aditall.log.logger");
}
....
_lc.send(_lcName, LOG, sender + JS_SEPARATOR + message);
....
static private function onLCStatusDelegate(infoObject:Object):Void
{
getURL(JS_TRACER + "[onStatus]" + JS_SEPARATOR + infoObject.level + " domain " + _lc.domain() + JS_CLOSE);
}
....
Here I'm trying to send a message to the LC in AIR logger, and if the attemt fails I print it into FireBug console... unfortunately it fails...
Any insights?