html 中 SWF 文件的高度和宽度
在下面的代码中,只有按钮图像被嵌入到flex代码中。但是在html对象或嵌入标签中,为什么必须指定高度和宽度。即使这是一个普通的按钮,如果我们不指定高度和宽度宽度似乎有一些错误
html
<div align="center">
<br />
<div style="display:block;width:100px;height:100px;" id="audio"
class="testsound" align="center"/>
<p class="clickable">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="400" height="100" id="myMovieName">
<param name="movie" value="/media/players/testsound.swf"/>
<param name="soundurl" value="/media/players/music.mp3"/>
<param name="quality" value="high"/>
<param name="bgcolor" value="#FFFFFF"/>
<embed width="100" height="100" href="/media/players/testsound.swf"
src="/media/players/testsound.swf"
flashvars="soundUrl=/media/players/music.mp3"
quality="high" bgcolor="#FFFFFF"
name="myMovieName" loop="false" align=""
type="application/x-shockwave-flash">
</embed>
</object>
</p>
</div>
MXML
<?xml version="1.0"?>
<!-- embed/EmbedSound.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import flash.media.*;
public var snd:Sound = new sndCls() as Sound;
public var sndChannel:SoundChannel;
public function playSound():void {
sndChannel=snd.play();
}
]]>
</mx:Script>
<mx:Image id="loader1" click="playSound();"
source="@Embed(source='/opt/cloodon/site/media/img/speaker.gif')" />
</mx:Application>
In the following code Only the button image has been embeded into the flex code.But in the html object or embed tag why the height and width has to be specified.Even though for this is a normal button if we do not specify the height and width there seems to be some error
html
<div align="center">
<br />
<div style="display:block;width:100px;height:100px;" id="audio"
class="testsound" align="center"/>
<p class="clickable">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="400" height="100" id="myMovieName">
<param name="movie" value="/media/players/testsound.swf"/>
<param name="soundurl" value="/media/players/music.mp3"/>
<param name="quality" value="high"/>
<param name="bgcolor" value="#FFFFFF"/>
<embed width="100" height="100" href="/media/players/testsound.swf"
src="/media/players/testsound.swf"
flashvars="soundUrl=/media/players/music.mp3"
quality="high" bgcolor="#FFFFFF"
name="myMovieName" loop="false" align=""
type="application/x-shockwave-flash">
</embed>
</object>
</p>
</div>
MXML
<?xml version="1.0"?>
<!-- embed/EmbedSound.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import flash.media.*;
public var snd:Sound = new sndCls() as Sound;
public var sndChannel:SoundChannel;
public function playSound():void {
sndChannel=snd.play();
}
]]>
</mx:Script>
<mx:Image id="loader1" click="playSound();"
source="@Embed(source='/opt/cloodon/site/media/img/speaker.gif')" />
</mx:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嵌入标签中的高度和宽度是必需的属性。请查看 swfobject 或 Adobe 标签定义以及 必需和可选属性。
您是否在问为什么它们是必需的,或者如果没有它们,为什么您的页面会崩溃(提示,第一个答案是第二个问题)?
编辑:
您应该将 EMBED 和 OBJECT 标记的宽度和高度属性修改为与 swf 的大小完全一致。
您可以在 .mxml 中设置应用程序的宽度和高度。
如果将scaleMode 设置为“noScale”,您将不会在 swf 中看到任何缩放。
如果您使用的是 Actionscript 3(您应该是),您可以在主类中设置元数据。
IE
Height and Width in an embed tag are required attributes. Have a gander at swfobject or Adobe on the tag definition as well as required and optional attributes.
Are you asking why they're required or why your page will break if you don't have them (hint, the first answer is the second question)?
EDIT:
You should modify the width and height attribute of the EMBED and OBJECT tags to be exactly to the size of the swf.
You can set your application width and height in the .mxml
If you set the scaleMode to "noScale" you won't see any scaling in your swf.
If you're in Actionscript 3 (which you should be), you can set the meta-data in your main class.
i.e.
您应该在主 mxml 中指定
Application
的宽度和高度,即使它仅包含可点击的图像!如果您希望页面具有
width: 400px
和height: 100px
的 Flex 图像(按钮?),那么您的Application
标签必须如下所示:尽管如此,在您的 html 中,您应该让
object
和embed
标签具有相同的width
和height
,并且您还应该为embed
标记的align
属性指定一个值,例如:align="middle"
。您的
object
标记应类似于Other
你的 sndClass 在哪里声明的?如果您嵌入了该 mp3,您的脚本标记应包含:
如果您想从 html 指定 mp3 的路径,您可以查看 这篇文章供参考。
更新 2
要根据 Flex 按钮的大小设置 html
object
的宽度和高度,您应该按如下方式更新应用程序 mxml 代码:请注意,最初此应用程序是只有 1x1 像素(如果小于,则不会初始化!)。
在
onCreationComplete
处理程序中,其大小会更改以匹配按钮的大小。这些值(宽度和高度)将传递给 JavaScript 函数
onFlashAppInited
,您还应该更新该函数:you should specify in your main mxml the width and height of your
Application
even though it contains but a clickable image!If you'd like your page to have a flex image (button??) of
width: 400px
andheight: 100px
, then yourApplication
tag must look like:And nonetheless, in your html you should have both your
object
andembed
tags to have the samewidth
andheight
, and you should specify a value to yourembed
tag'salign
attribute as well, eg:align="middle"
.Your
object
tag should look similar toOther
Where is your sndClass declared? If you have that mp3 embedded, your script tag should contain:
If you'd like to specify your mp3's path from html, you might look at this post for reference.
Update 2
To set the html
object
's width and height based on your flex button's size, you should update your application mxml code as follows:Note, that initially this application is only 1x1 pixel (if less, it won't initialize!).
In the
onCreationComplete
handler its size is changed to match the button's size.These values (width and height) are passed to the javascript function
onFlashAppInited
, which you should also update:添加@Dominic Tancredi 的评论:
OBJECT 和 EMBED 标记都需要 WIDTH 和 HEIGHT 属性。
Addition to @Dominic Tancredi's comment:
Both OBJECT and EMBED tags require WIDTH and HEIGHT attributes.