Flash与JavaScript信息交互

11/29/2006来源:Flash教程人气:13741

网上提供的这方面资料太少了,研究一两天,做了个例子,大家可以参考!


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Flash与3D信息交互</title>
<style type="text/CSS">
<!--
td {}{
    font-family: "宋体";
    font-size: 12px;
}
-->
</style>
</head>
<body onLoad="Init();">
  <p>
        <!--定义TerraExplorer的信息窗口对象-->
        <object ID="TEInformationWindow" classid="CLSID:3a4f9193-65a8-11d5-85c1-0001023952c1" width="300" height="400"></object>
        <!--定义一个TerraExplorer 3D窗口对象-->
        <object ID="TE3DWindow" classid="CLSID:3a4f9192-65a8-11d5-85c1-0001023952c1" width=650 height="400"></object>
        <!--定义TerraExplorer对象-->
        <object ID="TE" CLASSId="CLSID:3a4f9191-65a8-11d5-85c1-0001023952c1"></object>
 </p>

<table width="937" border="1" align="left">
  <tr>
    <td width="369" align="center">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="300" height="150" id="Flash1" align="middle">
            <param name="allowScriptaccess" value="sameDomain" />
            <param name="movie" value="f2.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <embed src="f2.swf" quality="high" bgcolor="#ffffff" width="300" height="150" name="Flash1"  swLiveConnect="true" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
        </object>
    </td>
<!--    -->
    <td width="282" align="center">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="300" height="150" id="myFlash" align="middle">
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="movie" value="f4.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ccffff" />
            <embed src="f4.swf" quality="high" bgcolor="#ccffff" width="300" height="150" name="myFlash" swLiveConnect="true" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
        </object>
    </td>
    <td width="264" colspan="2" align="left">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="btn1" width="100" height="50" align="middle">
            <param name="allowScriptAccess" value="sameDomain" />
            <param name="movie" value="btn1.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <embed src="btn1.swf" quality="high" bgcolor="#ffffff" width="100" height="50" swLiveConnect=true id="btn1" name="btn1" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
        </object>
 </td>
  </tr>
  <tr>
  <td width="369" height="200" align="center">
  </td></tr>
</table>
</html>
<script language="javaScript">
   
    var ITerraExplorer = null;
    var IPlane  = null;
    var IMenu  = null;
    var IObjectManager = null;
    var IRender=null;
    var ZoomMode = 0;
    var zoom_array = new Array();
    //浏览器设置
    var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
   
//初始化
function Init()
{
    var temp;
    ITerraExplorer = TE.interface("ITerraExplorer5");
    IPlane = TE.interface("IPlane5");
    IInformationTree = TE.interface("IInformationTree5");
    IMenu = TE.interface("IMenu");
    IObjectManager = TE.interface("IObjectManager5");
    ITerraExplorer.Load("2.fly");
    IRender=TE.interface("IRender5");
}
//飞到某个地方--------------------------------------------------------------------------------------------------
// 处理 Flash 影片中的所有 FSCommand 消息
function myFlash_DoFSCommand(args1,args2)   
{
    var myFlashObj = InternetExplorer ? myFlash : document.myFlash;
    var tX0,tZ0;
    tX0 =args1;
    tZ0 =args2;
   FlyToWhere(tX0,tZ0);
}
// Internet Explorer 的挂钩
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
    navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1)
{
    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('Sub myFlash_FSCommand(ByVal command, ByVal args)\n');
    document.write(' call myFlash_DoFSCommand(command, args)\n');
    document.write('end sub\n');
    document.write('</SCRIPT\> \n');
}

function FlyToWhere(tX0,tZ0)
{
    //创建文本对象
    var LabelInfo = new Object();
    LabelInfo.Text = "经度   :   "+tX0+"    纬度   :   "+tZ0;
    LabelInfo.Scale = 1;
    LabelInfo.BgColor = 236;

    IObjectManager.CreateLabel (LabelInfo, tX0, tZ0, 2000.0 );
    IPlane.FlyTo (tX0,tZ0,2000.0,117.98,0, -35,"Oval" );
}
//飞到某地------------------------------------------------------------------------------------------------------
function btn1_DoFSCommand(command, args) {
    var btn1Obj = InternetExplorer ? document.all.btn1 : document.btn1;
    var tX0;
    tX0 =args;
    klmy();
}
// Internet Explorer 的挂钩
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1)
{
    document.write('<script language=\"VBScript\"\>\n');
    document.write('On Error Resume Next\n');
    document.write('Sub btn1_FSCommand(ByVal command, ByVal args)\n');
    document.write('    Call btn1_DoFSCommand(command, args)\n');
    document.write('End Sub\n');
    document.write('</script\>\n');
}

function klmy()
{
    //创建文本对象
    var LabelInfo = new Object();
    LabelInfo.Text = "中国 "
    LabelInfo.Scale = 1;
    LabelInfo.BgColor = 236;

    IObjectManager.CreateLabel (LabelInfo, 87, 45, 2000.0 );
    IPlane.FlyTo (87,45,2000.0,117.98,0, -35,"Oval" );
}
//-------------------------------------------------------------------------------------------------------------------

</script>

<script language="vbscript">
function TE_OnFrame()
    dim x1,y1
    IRender.GetMouseInfo 1,x1,y1
    ObjType = 0
    IRender.ScreenToWorld x1,y1,ObjType,WorldX,WorldHeigth,WorldY,ObjectID
       window.document.Flash1.SetVariable "x", WorldX
    window.document.Flash1.SetVariable "y", WorldY
    end function
   
</script>

http://www.cnblogs.com/support/archive/2006/11/28/575473.html