Flex結合JavaScript讀取本地路徑的方法

來源:互聯網
上載者:User

mxml代碼
<!--ReadLocalFile.mxml-->
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[

private function init():void
{
ExternalInterface.addCallback("OnFileChange",frSelectHandler);//註冊JS回調
btnBrowser.addEventListener(MouseEvent.CLICK,mouseClickHandler);
}

private function mouseClickHandler(event:MouseEvent):void
{
ExternalInterface.call("Browser");//調用JS中Browser函數
}

private function frSelectHandler(path:String):void
{
imgTest.source = path;
}
]]>
</mx:Script>
<mx:Button id="btnBrowser" x="10" y="10" label="Button" />
<mx:Image id="imgTest" x="10" y="50"/>
</mx:Application>

html端代碼
<!-- ReadLocalFile.html -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="history/history.css" />
<title></title>
<script src="AC_OETags.js" language="javascript"></script>
<script src="history/history.js" language="javascript"></script>
<style>
body { margin: 0px; overflow:hidden }
</style>
<script language="JavaScript" type="text/javascript">
var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 28;
//關鍵代碼
function Browser()
{
document.getElementById("fileInput").click();
}
function OnFileChange()
{
thisMovie("ReadLocalFile").OnFileChange(document.getElementById("fileInput").value);
}
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
</script>
</head>
<body scroll="no">
<input type="file" id="fileInput" style="display:none" onchange="OnFileChange()" /><!--fileInput控制項-->
<script language="JavaScript" type="text/javascript">
var hasProductInstall = DetectFlashVer(6, 0, 65);
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if ( hasProductInstall && !hasRequestedVersion ) {
var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
var MMredirectURL = window.location;
document.title = document.title.slice(0, 47) + " - Flash Player Installation";
var MMdoctitle = document.title;
AC_FL_RunContent(
"src", "playerProductInstall",
"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "ReadLocalFile",
"quality", "high",
"bgcolor", "#869ca7",
"name", "ReadLocalFile",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else if (hasRequestedVersion) {
AC_FL_RunContent(
"src", "ReadLocalFile",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "ReadLocalFile",
"quality", "high",
"bgcolor", "#869ca7",
"name", "ReadLocalFile",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else { // flash is too old or we can't detect the plugin
var alternateContent = 'Alternate HTML content should be placed here. '
+ 'This content requires the Adobe Flash Player. '
+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
document.write(alternateContent); // insert non-flash content
}
</script>
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="ReadLocalFile" width="100%" height="100%"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="ReadLocalFile.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="ReadLocalFile.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="ReadLocalFile" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</noscript>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.