import { AssetEvent , AssetLibrary , URLLoaderEvent , IAsset , LoaderEvent , ParserEvent , URLRequest } from "@awayjs/core" ; import { MovieClip , Sprite , Font , TextField , TextFormat , TextFormatAlign , TextFieldAutoSize , MouseManager } from "@awayjs/scene" ; import { SWFParser } from "@awayfl/swf-loader" ; import { AVM1MovieClip , LoaderInfo , AVM1SceneGraphFactory , AVM1ContextImpl , SecurityDomain , AVM1Globals , AVMAwayStage } from "@awayfl/avm1" ; import { FontParser } from "@awayjs/parsers" ; class BSWFViewerMinimal_text { private _stage : AVMAwayStage ; private _avm1SceneGraphFactory : AVM1SceneGraphFactory ; /**
     * Constructor
     */ constructor ( ) { this . _stage = new AVMAwayStage ( window . innerWidth / 2 , window . innerHeight / 2 , 0xcccccc , 24 , null ) ; this . _stage . scene . mouseManager . _stage = this . _stage ; this . _stage . updateSize ( ( window . innerWidth - 550 ) / 2 , ( window . innerHeight - 450 ) / 2 , 550 , 450 ) ; var loaderInfo = new LoaderInfo ( ) ; loaderInfo . swfVersion = 6 ; this . _avm1SceneGraphFactory = new AVM1SceneGraphFactory ( new AVM1ContextImpl ( loaderInfo ) ) ; this . _avm1SceneGraphFactory . avm1Context . sec = new SecurityDomain ( ) ; this . _avm1SceneGraphFactory . avm1Context . setStage ( this . _stage , document ) ; AVM1Globals . _scenegraphFactory = this . _avm1SceneGraphFactory ; this . _onAssetCompleteDelegate = ( event ) => this . onAssetComplete ( event ) ; AssetLibrary . addEventListener ( AssetEvent . ASSET_COMPLETE , this . _onAssetCompleteDelegate ) ; AssetLibrary . addEventListener ( LoaderEvent . LOAD_COMPLETE , ( event ) => this . onLoadComplete ( event ) ) ; AssetLibrary . addEventListener ( URLLoaderEvent . LOAD_ERROR , ( event ) => this . onLoadError ( event ) ) ; AssetLibrary . addEventListener ( ParserEvent . PARSE_ERROR , ( event ) => this . onParseError ( event ) ) ; AssetLibrary . load ( new URLRequest ( "assets/georgia.ttf" ) , null , null , new FontParser ( true ) ) ; var myThis = this ; window . addEventListener ( "keydown" , function ( event ) { if ( event . key == "Tab" ) { myThis . _stage . scene . mouseManager . focusNextTab ( ) ; } } ) ; } private _onAssetCompleteDelegate : ( event : AssetEvent ) => void ; private onAssetComplete2 ( event ) { var asset = event . asset ; if ( asset . isAsset ( MovieClip ) ) { if ( asset . name == "scene" ) { this . _stage . getLayer ( 0 ) . addChild ( < MovieClip > asset ) ; ( < AVM1MovieClip > ( < MovieClip > asset ) . adapter ) . initAdapter ( ) ; ( < MovieClip > asset ) . alpha = 0.5 ; } } } private onAssetComplete ( event ) { var asset = event . asset ; if ( asset . isAsset ( Font ) ) { console . log ( "loaded a font" ) ; var mySprite = new Sprite ( ) ; var _tf = new TextField ( ) ; var newFormat = new TextFormat ( ) ; _tf . textFormat = newFormat ; _tf . border = true ; _tf . x = 25 ; _tf . y = 25 ; _tf . width = 440 ; _tf . height = 355 ; _tf . borderColor = 0xff0000 ; _tf . textFormat . font = < Font > asset ; _tf . textFormat . color = 0xff0000 ; _tf . textFormat . size = 72 ; _tf . textFormat . align = TextFormatAlign . CENTER ; _tf . autoSize = TextFieldAutoSize . NONE ; _tf . text = "AwayJS\ntext-test\nSWF VS TTF" ; mySprite . addChild ( _tf ) ; this . _stage . getLayer ( 0 ) . addChild ( mySprite ) ; } } private cnt : number = 0 ; private onLoadComplete ( event ) { AssetLibrary . removeEventListener ( AssetEvent . ASSET_COMPLETE , this . _onAssetCompleteDelegate ) ; AssetLibrary . addEventListener ( AssetEvent . ASSET_COMPLETE , ( event ) => this . onAssetComplete2 ( event ) ) ; if ( this . cnt == 0 ) AssetLibrary . load ( new URLRequest ( "assets/SWF/text_test.swf" ) , null , null , new SWFParser ( this . _avm1SceneGraphFactory ) ) ; this . cnt ++ ; } private onLoadError ( event ) { console . log ( "Loading error" , event ) ; } private onParseError ( event ) { console . log ( "Parsing error" , event ) ; } } window . onload = function ( ) { ( < HTMLElement > document . getElementsByTagName ( "BODY" ) [ 0 ] ) . style . overflow = "hidden" ; new BSWFViewerMinimal_text ( ) ; } ;