SWF未按HTML中的指定显示

时间:2012-08-19 12:19:08

标签: actionscript-3 flash flash-builder

我有一个FlashBuilder项目,我只想通过html文件设置显示的大小(在浏览器中)。我不想在flash代码中硬编码swf的大小。 此外,我需要提供闪存变量的几个参数。 我的html是FlashBuilder生成的标准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像素)。

我做错了什么?

1 个答案:

答案 0 :(得分: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>