UNPKG

@awayfl/avm2

Version:

Virtual machine for executing AS3 code

59 lines (58 loc) 2.4 kB
import { AVMVERSION, release, ExternalInterfaceService } from '@awayfl/swf-loader'; import { AVM2LoadLibrariesFlags } from './AVM2LoadLibrariesFlags'; import { initSystem } from './natives/system'; import { initlazy } from './abc/lazy'; import { initializeAXBasePrototype } from './run/initializeAXBasePrototype'; var AVM2Handler = /** @class */ (function () { function AVM2Handler(playerglobal) { this.avmVersion = AVMVERSION.AVM2; if (!playerglobal) throw ('AVM2Handler must be init with a valid PlayerGlobal-class'); this._playerglobal = playerglobal; } AVM2Handler.prototype.init = function (avmStage, swfFile, callback) { var _this = this; if (this._avmStage) { callback(false); } this._avmStage = avmStage; initSystem(); initializeAXBasePrototype(); initlazy(); // Add the |axApply| and |axCall| methods on the function prototype so that we can treat // Functions as AXCallables. Function.prototype.axApply = Function.prototype.apply; Function.prototype.axCall = Function.prototype.call; this._playerglobal.createSecurityDomain(avmStage, swfFile, AVM2LoadLibrariesFlags.Builtin | AVM2LoadLibrariesFlags.Playerglobal).then(function (factory) { release || console.log('playerglobal has init'); _this._factory = factory; if (_this._avmStage.config.externalInterfaceID) { ExternalInterfaceService.interfaceID = _this._avmStage.config.externalInterfaceID; } callback(true); }); }; AVM2Handler.prototype.dispose = function () { this._playerglobal.dispose(); }; AVM2Handler.prototype.enterFrame = function (dt) { this._playerglobal.enterFrame(); }; AVM2Handler.prototype.resizeStage = function () { this._playerglobal.resizeStage(); }; Object.defineProperty(AVM2Handler.prototype, "factory", { get: function () { if (!this._factory) throw ('AVM2Handler - no Factory get factory'); return this._factory; }, enumerable: false, configurable: true }); AVM2Handler.prototype.addAsset = function (asset, addScene) { this._playerglobal.addAsset(asset, addScene); }; return AVM2Handler; }()); export { AVM2Handler };