1

我有一个 FlashBuilder 项目,我只想通过 html 文件设置显示的大小(在浏览器中)。我不想在 flash 代码中硬编码 swf 的大小。我还需要为 flash vars 提供几个参数。我的 html 是 Fl​​ashBuilder 生成的标准 html 代码的修改版本。我尝试在 JavaScript 中设置 swf 的大小并使用容器 div。所以我有以下 html 代码来显示 swf:

<html>   
<head>
    <title></title>
    <style type="text/css" media="screen">
        html, body {
            height:100%;
        }
        body {
            margin:0;
            padding:0;
            overflow:auto;
            text-align:center;
            background-color: #ffffff;
        }
        object:focus {
            outline:none;
        }
        #flashContent {
            display:none;
        }
    </style>
    <!-- Enable Browser History by replacing useBrowserHistory tokens
    with two hyphens -->
    <!-- BEGIN Browser History required section -->
    <link rel="stylesheet" type="text/css" href="history/history.css" />
    <script type="text/javascript" src="history/history.js"></script>
    <!-- END Browser History required section -->
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">
        var swfVersionStr = "11.1.0";
        // To use express install, set to playerProductInstall.swf, otherwise the empty string. 
        var xiSwfUrlStr = "playerProductInstall.swf";
        var flashvars = {};
        var params = {};
        var attributes = {};
        flashvars.json = "some json file.json";
        flashvars.width = "900";
        flashvars.height = "480";
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "sameDomain";
        params.allowfullscreen = "true";
        params.wmode = "direct";
        attributes.id = "Main";
        attributes.name = "Main";
        attributes.align = "left";
        swfobject.embedSWF("Main.swf", "flashContent", "100%", "100%",
        swfVersionStr, xiSwfUrlStr,
        flashvars, params, attributes);
        // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
        swfobject.createCSS("#flashContent", "display:block;text-align:left");
    </script>
</head>

<body>
    <div style="display:block;text-align:left;width:900px; height:480px; position:absolute; top:50px; left:100px">
        <div id="flashContent">
            <p>To view this page ensure that Adobe Flash Player version 11.1.0 or greater
                is installed.</p>
            <script type="text/javascript">
                var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
                document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='" + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>");
            </script>
        </div>
    </div>
</body>
</html>

我的 Flash 主要方法中的以下内容:

public function Main(){

    swfWidth = LoaderInfo(root.loaderInfo).parameters.width;
    swfHeight = LoaderInfo(root.loaderInfo).parameters.height;
    swfFrameRate = LoaderInfo(root.loaderInfo).parameters.framerate;

    json = LoaderInfo(root.loaderInfo).parameters.json;
    loadJsonFile(json); 

    stage.frameRate = swfFrameRate;
    stage.scaleMode = StageScaleMode.NO_SCALE;

    view = new View3D();
    view.width = swfWidth;
    view.height = swfHeight;
    camera = view.camera; 
    cameraController = new HoverController(camera, null, 150, 10, 10);
    this.addChild(view); 
}

但是,当我在浏览器中打开它时,显示的大小与 hmtl 中给出的大小不匹配(使用上面的代码,它会导致大约 700x430 像素)。

我究竟做错了什么?

4

1 回答 1

1

最后,我设法修复它。问题是由 Flashbuilder 创建的 Main.html 和 index.template.html (这不容易修改,因为它非常复杂,并且比实际需要的更详细。

我在这个生成器的帮助下创建了一个新的 .html 文件:http: //www.bobbyvandersluis.com/swfobject/generator/index.html

..现在舞台设置为由 flashVars 提供。

这就是我的 Main 现在的样子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">
        swfobject.registerObject("Main", "11.0.0", "expressInstall.swf");
    </script>
</head>
<body>
    <div>
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="850" height="480" id="Main">
            <param name="movie" value="Main.swf" />
            <param name="quality" value="best" />
            <param name="scale" value="noscale" />
            <param name="salign" value="tl" />
            <param name="wmode" value="direct" />
            <param name="bgcolor" value="#cccccc" />
            <param name="allowfullscreen" value="true" />
            <param name="allowscriptaccess" value="always" />
            <param name="allownetworking" value="all" />
            <param name="flashvars" value="json=../somejsonFile.json&amp;width=850&amp;height=480&framerate=60" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="Main.swf" width="850" height="480">
                <param name="quality" value="best" />
                <param name="scale" value="noscale" />
                <param name="salign" value="tl" />
                <param name="wmode" value="direct" />
                <param name="bgcolor" value="#cccccc" />
                <param name="allowfullscreen" value="true" />
                <param name="allowscriptaccess" value="always" />
                <param name="allownetworking" value="all" />
                <param name="flashvars" value="json=../somejsonFilejson&amp;width=850&amp;height=480&framerate=60" />
            <!--<![endif]-->
                <a href="http://www.adobe.com/go/getflashplayer">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>
    </div>
</body>
</html>
于 2012-08-29T09:59:09.237 回答