日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
技術(shù)前沿如何在Flex中嵌入完整HTML頁面

Flex有很多值得學(xué)習(xí)的地方,本文和大家重點討論一下如何在Flex中嵌入完整HTML頁面,有時候我們需要在Flex應(yīng)用中嵌入HTML代碼,根據(jù)嵌入HTML要求的不同有兩種方法,請看下文詳細(xì)介紹。

目前創(chuàng)新互聯(lián)公司已為成百上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、沅江網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

在Flex中嵌入完整HTML頁面

有時候我們需要在Flex應(yīng)用中嵌入HTML代碼,根據(jù)嵌入HTML要求的不同有以下兩種方法:

1、Flex文本組件(Label、Text、TextArea)的htmlText屬性支持一些基本的HTML代碼,例如:

 
 
 
 
  1.  
  2.  
  3.  
  4. thisisahtmlcode

     
  5. ]]> 
  6.  
  7.  
  8.  

 2、我們可以將Flex應(yīng)用嵌入到HTML頁面中,然后通過Flex2中的ExternalInterface(Flex1.5使用getURL("javascript:javascriptMethod"))

來實現(xiàn)Flex與HTMLjavascript的相互交互,進一步的,如果要在Flex應(yīng)用中嵌入完整的HTML呢?

其實實現(xiàn)的方法很簡單,只需要使用HTML的Iframe標(biāo)簽來導(dǎo)入需嵌入的HTML頁面,然后使用ExternalInterface調(diào)用相應(yīng)的javasript將該Iframe移動到我們Flex頁面需要嵌入HTML頁面的部分之上就可以了,示意圖如下:

也就是說,我們包含F(xiàn)lexSWF文件的HTML頁面主要有三個部分:

1、Flexswf插件容器,F(xiàn)lexBuilder自動生成部分

 
 
 
 
  1. id="IFrameDemo"width="100%"height="100%" 
  2. codebase="http://download.macromedia.com/pub/shockwave/  
  3. cabs/flash/swflash.cab"> 
  4.  
  5.  
  6.  
  7. width="100%"height="100%"name="detectiontest" 
  8. aligh="middle" 
  9. play="true"loop="false"quality="high" 
  10. allowScriptAccess="sameDomain" 
  11. type="application/x-shockwave-flash" 
  12. wmode="opaque" 
  13. swLiveConnect="true" 
  14. pluginspage="http://www.macromedia.com/go/getflashplayer"> 
  15.  
  16.  
  17.  

 2、HTMLIframe標(biāo)簽,絕對定位,用來導(dǎo)入HTML頁面

 
 
 
 
  1. style="position:absolute;background-color:transparent;border:0px;visibility:hidden;"/> 

3、移動Iframe和在Iframe中導(dǎo)入需嵌入FLEX中的HTML頁面的腳本

 
 
 
 
  1.  
  2.  

 Flex中的導(dǎo)入Iframe頁面和移動Iframe的代碼如下:

 
 
 
 
  1. importflash.external.ExternalInterface;  
  2. importflash.geom.Point;  
  3. importflash.net.navigateToURL;  
  4. privatevar__source:String;  
  5. privatefunctionmoveIFrame():void{  
  6. varlocalPt:Point=newPoint(0,0);  
  7. varglobalPt:Point=this.localToGlobal(localPt);  
  8. ExternalInterface.call("moveIFrame",globalPt.x,globalPt.y,this.width,this.  
  9. height);  
  10. }  
  11. publicfunctionsetsource(source:String):void{  
  12. if(source){  
  13. if(!ExternalInterface.available)  
  14. {  
  15. //TODO:determineifthisErrorisactuallyneeded.Thedebugger  
  16. //buildgivestheerrorbelow.Assumingthatthiserrorwillnotshow  
  17. //upinthereleasebuildbuthaven’tchecked.  
  18. thrownewError("TheExternalInterfaceisnotavailableinthiscontainer.  
  19. InternetExplorerActiveX,  
  20. Firefox,Mozilla1.7.5andgreater,orotherbrowsersthatsupportNPRuntimearerequired.");  
  21. }  
  22. __source=source;  
  23. ExternalInterface.call("loadIFrame",source);  
  24. }  
  25. }  

#p#兩個方法分別直接調(diào)用使用ExternalInterface.call調(diào)用前面我們提到的HTML頁面上的兩個Javascript方法。另外一個要注意的是
繼承自flash.display.DisplayObject類的localToGlobal方法的使用,該方法將基于Flash場景的坐標(biāo)轉(zhuǎn)換為基于全局本地坐標(biāo),也就是瀏覽器頁面坐標(biāo):

//Flash場景0,0坐標(biāo)varlocalPt:Point=newPoint(0,0);//轉(zhuǎn)換為瀏覽器頁面坐標(biāo)varglobalPt:Point=this.localToGlobal(localPt);
這樣就可以在Flex頁面中嵌入任意的HTML頁面了,為了方便,Brian寫了個嵌入HTML頁面的代理IFrame組件,該組件封裝了所有需要的Flex端代碼:
 

 
 
 
 
  1.  
  2. resize="callLater(moveIFrame)" 
  3. move="callLater(moveIFrame)"> 
  4.  
  5. importflash.external.ExternalInterface;  
  6. importflash.geom.Point;  
  7. importflash.net.navigateToURL;  
  8. privatevar__source:String;  
  9. privatefunctionmoveIFrame():void{  
  10. varlocalPt:Point=newPoint(0,0);  
  11. varglobalPt:Point=this.localToGlobal(localPt);  
  12. ExternalInterface.call("moveIFrame",globalPt.x,globalPt.y,this.width,this.height);  
  13. }  
  14. publicfunctionsetsource(source:String):void{  
  15. if(source){  
  16. if(!ExternalInterface.available)  
  17. {  
  18. //TODO:determineifthisErrorisactuallyneeded.Thedebugger  
  19. //buildgivestheerrorbelow.Assumingthatthiserrorwillnotshow  
  20. //upinthereleasebuildbuthaven’tchecked.  
  21. thrownewError("TheExternalInterfaceisnotavailableinthiscontainer.
  22. InternetExplorerActiveX,Firefox,  
  23. Mozilla1.7.5andgreater,orotherbrowsersthatsupportNPRuntimearerequired.");  
  24. }  
  25. __source=source;  
  26. ExternalInterface.call("loadIFrame",source);  
  27. }  
  28. }  
  29. publicfunctiongetsource():String{  
  30. return__source;  
  31. }  
  32. overridepublicfunctionsetvisible(visible:Boolean):void{  
  33. super.visible=visible;  
  34. if(visible)  
  35. {  
  36. ExternalInterface.call("showIFrame");  
  37. }  
  38. else  
  39. {  
  40. ExternalInterface.call("hideIFrame");  
  41. }  
  42. }  
  43.  
  44. ]]> 
  45.  
  46.  
  47.  

該IFrame組件有個source屬性用來記錄需要載入的嵌入HTML頁面的地址,每次source屬性更新時,調(diào)用ExternalInterface.call("loadIFrame",source)
調(diào)用javascript方法loadIFrame方法在HTML頁面中的IFrame中載入要嵌入的HTML頁面。
另外,重載了Canvas的visible屬性,以便在Canvas隱藏HTML頁面中的IFrame。
如下使用該組件在Flex應(yīng)用中嵌入HTML頁面方法:

 
 
 
 
  1.  


分享文章:技術(shù)前沿如何在Flex中嵌入完整HTML頁面
當(dāng)前網(wǎng)址:http://www.5511xx.com/article/cdppsei.html