用DHTML中的ActionScript替换JavaScript
我需要写一个DHTML页面。但是,由于我在AS3库中拥有大部分代码,所以我想使用ActionScript而不是JavaScript来完成大部分工作。在这种情况下,JavaScript层(如果有的话)将只是一个写一次的抽象代理 我知道用DHTML中的ActionScript替换JavaScript,javascript,actionscript,dhtml,Javascript,Actionscript,Dhtml,我需要写一个DHTML页面。但是,由于我在AS3库中拥有大部分代码,所以我想使用ActionScript而不是JavaScript来完成大部分工作。在这种情况下,JavaScript层(如果有的话)将只是一个写一次的抽象代理 我知道ExternalInterface之类的东西,但我想要更高级的东西,这将简化JS代理层的创建 有什么建议吗?我以前在ActionScript和JavaScript之间做过一个事件驱动网关接口: IGateway.as package gateway { imp
ExternalInterface
之类的东西,但我想要更高级的东西,这将简化JS代理层的创建
有什么建议吗?我以前在ActionScript和JavaScript之间做过一个事件驱动网关接口: IGateway.as
package gateway {
import GatewayEvent;
public interface IGateway {
function send(event:GatewayEvent):void;
function receive(event:GatewayEvent):void;
}
}
package gateway
{
import flash.events.Event;
public class GatewayEvent extends Event {
public var message:Object;
public var flashId:String;
public static const APP_START:String = 'appStart';
public static const APP_END:String = 'appEnd';
public static const APP_READY:String = 'appReady';
public function GatewayEvent(flashId:String, type:String, message:Object = null) {
super(type, false, false);
this.flashId = flashId;
this.message = message;
}
}
}
package gateway {
import flash.external.ExternalInterface;
import flash.events.EventDispatcher;
import GatewayEvent;
import IGateway;
public class Gateway extends EventDispatcher implements IGateway {
private static const _instance:Gateway = new Gateway(SingletonLock);
public function Gateway(lock:Class) {
if (lock != SingletonLock) {
throw new Error("invalid Singleton access.")
}
if (ExternalInterface.available) {
ExternalInterface.addCallback('relayEvent', relayEvent);
}
}
public static function get instance():Gateway {
return _instance;
}
public function send(event:GatewayEvent):void{
if (ExternalInterface.available) {
ExternalInterface.call("$.gateway.receive", event.flashId, event.type, event.message);
}
}
public function receive(event:GatewayEvent):void{
dispatchEvent(event);
}
protected function relayEvent(flashId:String, type:String, message:Object):void {
Gateway.instance.receive(new GatewayEvent(flashId, type, message));
}
}
}
class SingletonLock {}
网关事件。作为
package gateway {
import GatewayEvent;
public interface IGateway {
function send(event:GatewayEvent):void;
function receive(event:GatewayEvent):void;
}
}
package gateway
{
import flash.events.Event;
public class GatewayEvent extends Event {
public var message:Object;
public var flashId:String;
public static const APP_START:String = 'appStart';
public static const APP_END:String = 'appEnd';
public static const APP_READY:String = 'appReady';
public function GatewayEvent(flashId:String, type:String, message:Object = null) {
super(type, false, false);
this.flashId = flashId;
this.message = message;
}
}
}
package gateway {
import flash.external.ExternalInterface;
import flash.events.EventDispatcher;
import GatewayEvent;
import IGateway;
public class Gateway extends EventDispatcher implements IGateway {
private static const _instance:Gateway = new Gateway(SingletonLock);
public function Gateway(lock:Class) {
if (lock != SingletonLock) {
throw new Error("invalid Singleton access.")
}
if (ExternalInterface.available) {
ExternalInterface.addCallback('relayEvent', relayEvent);
}
}
public static function get instance():Gateway {
return _instance;
}
public function send(event:GatewayEvent):void{
if (ExternalInterface.available) {
ExternalInterface.call("$.gateway.receive", event.flashId, event.type, event.message);
}
}
public function receive(event:GatewayEvent):void{
dispatchEvent(event);
}
protected function relayEvent(flashId:String, type:String, message:Object):void {
Gateway.instance.receive(new GatewayEvent(flashId, type, message));
}
}
}
class SingletonLock {}
Gateway.as
package gateway {
import GatewayEvent;
public interface IGateway {
function send(event:GatewayEvent):void;
function receive(event:GatewayEvent):void;
}
}
package gateway
{
import flash.events.Event;
public class GatewayEvent extends Event {
public var message:Object;
public var flashId:String;
public static const APP_START:String = 'appStart';
public static const APP_END:String = 'appEnd';
public static const APP_READY:String = 'appReady';
public function GatewayEvent(flashId:String, type:String, message:Object = null) {
super(type, false, false);
this.flashId = flashId;
this.message = message;
}
}
}
package gateway {
import flash.external.ExternalInterface;
import flash.events.EventDispatcher;
import GatewayEvent;
import IGateway;
public class Gateway extends EventDispatcher implements IGateway {
private static const _instance:Gateway = new Gateway(SingletonLock);
public function Gateway(lock:Class) {
if (lock != SingletonLock) {
throw new Error("invalid Singleton access.")
}
if (ExternalInterface.available) {
ExternalInterface.addCallback('relayEvent', relayEvent);
}
}
public static function get instance():Gateway {
return _instance;
}
public function send(event:GatewayEvent):void{
if (ExternalInterface.available) {
ExternalInterface.call("$.gateway.receive", event.flashId, event.type, event.message);
}
}
public function receive(event:GatewayEvent):void{
dispatchEvent(event);
}
protected function relayEvent(flashId:String, type:String, message:Object):void {
Gateway.instance.receive(new GatewayEvent(flashId, type, message));
}
}
}
class SingletonLock {}
messenger.js(需要jquery)