htmlsprite是一个Flash用来解析HTML文档的开发包。
示例代码:
importcom.redurban.HTMLSpritevarhtmlsprite:HTMLSprite=newHTMLSprite();////staticdebugmodeon/offHTMLSprite.debug=true;////Usethiseventwhenloadingbothstylesheetandhtmlfilehtmlsprite.addEventListener(HTMLSprite.LOADCOMPLETE,LoadComplete);////Thiseventwillbedispatchedwhentherenderingiscompletehtmlsprite.addEventListener(HTMLSprite.RENDERCOMPLETE,RenderComplete);////Usethiseventwhenloadingastylesheetfileonly//Willbedispatchedwhentheloadiscompleted.htmlsprite.addEventListener(HTMLSprite.STYLECOMPLETE,StyleComplete);////Usethiseventwhenloadingaexternalhtmlfileonly,//Willbedispatchedwhentheloadiscompleted.htmlsprite.addEventListener(HTMLSprite.HTMLCOMPLETE,HtmlComplete);////Thiseventwillbedispatchedwhenanexternallinkisclick//<ahref="event:internalEvent">Example</a>htmlsprite.addEventListener(HTMLSprite.LINK,Link); //Examplehtmlfile+cssfile//htmlsprite.Load("html/indexwithoutcss.htm","html/style.css"); //Examplestylesheetfileonly//htmlsprite.LoadStylesheet("html/style.css"); //Examplehtmlfileonly//htmlsprite.Load("html/index.htm"); //Examplehtmltext+stylesheettextvarstylesheet:StyleSheet=newStyleSheet();stylesheet.setStyle(".header",{fontFamily:"Arial",color:"#000000"});stylesheet.setStyle("body",{fontFamily:"Arial"});stylesheet.setStyle("div",{fontFamily:"Arial",fontSize:"20px",backgroundColor:"#efefef"});htmlsprite.stylesheet=stylesheet;htmlsprite.html="Hello<br/>world!";htmlsprite.Render();////LinkListenerpublicfunctionLink(evt:LinkEvent){varlinkType:String=evt.data.type;varlinkValue:String=evt.data.value;varlinkTarget:String=evt.data.target; trace("linktype:"+linkType+",linkvalue:"+linkValue+",linktarget:"+linkTarget);}////LoadCompleteListener//It'simportantthatyourenderthehtmlafterthestylesheet//andhtmlfilehasbeenloadedpublicfunctionLoadComplete(evt:Event){htmlsprite.Render();}//LoadStylesheetComplete//DonotusethislistenerwhenyouuseanexternalstylesheetANDexternalHTML.//YoucanusethentheLoadCompleteExamplepublicfunctionStyleComplete(evt:Event){htmlsprite.html="hello<br/>world";htmlsprite.Render();}//LoadHTMLComplete//DonotusethislistenerwhenyouuseanexternalstylesheetANDexternalHTML.//YoucanusethentheLoadCompleteExample publicfunctionHtmlComplete(evt:Event){htmlsprite.stylesheet=stylesheet;htmlsprite.Render();} //Rendercomplete//Atthispointit'ssafetodeterminewidthandheightofthesprite//andaddittothedisplaylistpublicfunctionRenderComplete(evt:Event){addChild(htmlsprite);}
评论