Flex JS 结合做弹出“打开文件对话框”

 文件ReadLocalFile.mxml

 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
  3. <mx:Script>
  4.      <![CDATA[
  5.        import flash.external.*;
  6.        private function init():void
  7.        {
  8.            ExternalInterface.addCallback("OnFileChange",frSelectHandler);//注册JS回调
  9.            btnBrowser.addEventListener(MouseEvent.CLICK,mouseClickHandler);
  10.            //test1.text = "1";
  11.        }
  12.       
  13.        private function mouseClickHandler(event:MouseEvent):void
  14.        {
  15.            ExternalInterface.call("Browser");//调用JS中Browser函数
  16.            //test1.text = "2";
  17.        }
  18.       
  19.        private function frSelectHandler(path:String):void
  20.        {
  21.            imgTest.source = path;
  22.            test1.text = path;
  23.        }
  24.      ]]>
  25. </mx:Script>
  26.      
  27.      <mx:Panel title="TitleWindow Container Example" height="75%" width="75%" 
  28.         paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
  29.         <mx:Button id="btnBrowser" x="10" y="10" label="Button"/>
  30.         <mx:Image id="imgTest"   x="10" y="50"/>
  31.         <mx:Text id="test1" width="100%" />
  32.     </mx:Panel>
  33. </mx:Application>

文件ReadLocalFile.html

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html lang="en">
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.         <link rel="stylesheet" type="text/css" href="history/history.css" />
  6.         <title></title>
  7.         <script src="AC_OETags.js" language="javascript"></script>
  8.         <script src="history/history.js" language="javascript"></script>
  9.         <style>
  10. body {
  11.     margin: 0px;
  12.     overflow: hidden
  13. }
  14. </style>
  15.         <script language="JavaScript" type="text/javascript">
  16. var requiredMajorVersion = 9;
  17. var requiredMinorVersion = 0;
  18. var requiredRevision = 28;
  19. //关键代码
  20. function Browser()
  21. {
  22. //alert(document.getElementById("fileInput").value);
  23. document.getElementById("fileInput").click();
  24. }
  25. function OnFileChange()
  26. {
  27. //alert(document.getElementById("fileInput").value);
  28. thisMovie("ReadLocalFile").OnFileChange(document.getElementById("fileInput").value);
  29. }
  30. function thisMovie(movieName) {
  31.          if (navigator.appName.indexOf("Microsoft") != -1) {
  32.              return window[movieName];
  33.          } else {
  34.              return document[movieName];
  35.          }
  36.      }
  37. </script>
  38.     </head>
  39.     <body scroll="no">
  40.         <input name="fileIn" type="file" id="fileInput" style="display:none"
  41.             onchange="OnFileChange()" />
  42.         <!--fileInput关键代码-->
  43.         <script language="JavaScript" type="text/javascript">
  44. var hasProductInstall = DetectFlashVer(6, 0, 65);
  45. var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  46. if ( hasProductInstall && !hasRequestedVersion ) {
  47. var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
  48. var MMredirectURL = window.location;
  49.      documentdocument.title = document.title.slice(0, 47) + " - Flash Player Installation";
  50.      var MMdoctitle = document.title;
  51. AC_FL_RunContent(
  52.    "src", "playerProductInstall",
  53.    "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
  54.    "width", "100%",
  55.    "height", "100%",
  56.    "align", "middle",
  57.    "id", "ReadLocalFile",
  58.    "quality", "high",
  59.    "bgcolor", "#869ca7",
  60.    "name", "ReadLocalFile",
  61.    "allowScriptAccess","sameDomain",
  62.    "type", "application/x-shockwave-flash",
  63.    "pluginspage", "http://www.adobe.com/go/getflashplayer"
  64. );
  65. } else if (hasRequestedVersion) {
  66. AC_FL_RunContent(
  67.    "src", "ReadLocalFile",
  68.    "width", "100%",
  69.    "height", "100%",
  70.    "align", "middle",
  71.    "id", "ReadLocalFile",
  72.    "quality", "high",
  73.    "bgcolor", "#869ca7",
  74.    "name", "ReadLocalFile",
  75.    "allowScriptAccess","sameDomain",
  76.    "type", "application/x-shockwave-flash",
  77.    "pluginspage", "http://www.adobe.com/go/getflashplayer"
  78. );
  79.    } else {   // flash is too old or we can't detect the plugin
  80.      var alternateContent = 'Alternate HTML content should be placed here. '
  81.    + 'This content requires the Adobe Flash Player. '
  82.      + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
  83.      document.write(alternateContent);   // insert non-flash content
  84.    }
  85. </script>
  86.         <noscript>
  87.             <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  88.                 id="ReadLocalFile" width="100%" height="100%"
  89.                 codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
  90.                 <param name="movie" value="ReadLocalFile.swf" />
  91.                 <param name="quality" value="high" />
  92.                 <param name="bgcolor" value="#869ca7" />
  93.                 <param name="allowScriptAccess" value="sameDomain" />
  94.                 <embed src="ReadLocalFile.swf" quality="high" bgcolor="#869ca7"
  95.                     width="100%" height="100%" name="ReadLocalFile" align="middle"
  96.                     play="true" loop="false" quality="high"
  97.                     allowScriptAccess="sameDomain" type="application/x-shockwave-flash"
  98.                     pluginspage="http://www.adobe.com/go/getflashplayer">
  99.                 </embed>
  100.             </object>
  101.         </noscript>
  102.     </body>
  103. </html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 HTML 中创建弹对话框,您可以使用 JavaScript 和 CSS。以下是一个示例: ```html <!DOCTYPE html> <html> <head> <style> /* 样式用于显示对话框 */ .dialog-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center; } .dialog-box { background-color: #fff; padding: 20px; border-radius: 5px; max-width: 400px; text-align: center; } /* 隐藏对话框的初始状态 */ .dialog-overlay.hidden { display: none; } </style> </head> <body> <button onclick="openDialog()">打开对话框</button> <div id="dialog" class="dialog-overlay hidden"> <div class="dialog-box"> <h2>这是一个弹对话框</h2> <p>这是对话框中的内容。</p> <button onclick="closeDialog()">关闭</button> </div> </div> <script> function openDialog() { var dialog = document.getElementById('dialog'); dialog.classList.remove('hidden'); } function closeDialog() { var dialog = document.getElementById('dialog'); dialog.classList.add('hidden'); } </script> </body> </html> ``` 在上面的示例中,我们使用了一个按钮来触发打开对话框的操作。当按钮被点击时,`openDialog()` 函数会从 CSS 中移除对话框元素的 `hidden` 类,以显示对话框对话框的内容包含在一个具有 `dialog-box` 类的 `<div>` 元素中。您可以根据需要自定义对话框的样式和内容。 关闭对话框的操作是通过点击对话框中的关闭按钮来触发的。`closeDialog()` 函数会向对话框元素添加 `hidden` 类,以将其隐藏起来。 保存上述代码为 HTML 文件,并在浏览器中打开以查看效果。当您点击按钮时,将会显示一个弹对话框,点击关闭按钮将隐藏对话框
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值