html中SWF文件的高度和宽度
在下面的代码中,只有按钮图像嵌入到flex代码中。但是在html对象或嵌入标记中,为什么必须指定高度和宽度。即使这是一个正常的按钮,如果我们不指定高度和宽度,似乎也有一些错误html中SWF文件的高度和宽度,html,actionscript-3,flash,mxmlc,Html,Actionscript 3,Flash,Mxmlc,在下面的代码中,只有按钮图像嵌入到flex代码中。但是在html对象或嵌入标记中,为什么必须指定高度和宽度。即使这是一个正常的按钮,如果我们不指定高度和宽度,似乎也有一些错误 html <div align="center"> <br /> <div style="display:block;width:100px;height:100px;" id="audio" class="testsound" align="center"/
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>
嵌入标记中的高度和宽度是必需的属性。在标签定义上有一个gander,以及 您是否在问为什么需要它们,或者如果没有它们,为什么页面会断开(提示,第一个答案是第二个问题) 编辑: 您应该修改嵌入标记和对象标记的宽度和高度属性,使其与swf的大小完全一致 您可以在.mxml中设置应用程序的宽度和高度
<mx:Application width="300" height="200">
如果您使用的是ActionScript3(应该是),那么可以在主类中设置元数据
i、 e
除了@Dominic Tancredi的评论之外:
对象标记和嵌入标记都需要宽度和高度属性。您应该在主mxml中指定
应用程序的宽度和高度,即使它只包含可单击的图像
如果您希望您的页面具有宽度为400px、高度为100px的flex图像(按钮??),则您的应用程序标记必须如下所示:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="100">
其他
您的sndClass在哪里声明?如果已嵌入mp3,则脚本标记应包含:
<mx:Script>
<![CDATA[
import mx.core.SoundAsset;
[Embed('/media/players/music.mp3')]
private var _sound:Class;
public var snd:SoundAsset = new _sound() as SoundAsset;
public var sndChannel:SoundChannel;
public function playSound():void {
sndChannel=snd.play();
}
]]>
</mx:Script>
请注意,最初该应用程序仅为1x1像素(如果小于1x1像素,则不会初始化!)
在onCreationComplete
处理程序中,其大小将更改为与按钮大小匹配
这些值(宽度和高度)将传递给javascript函数onFlashAppInited
,您还应更新该函数:
function onFlashAppInited(width, height) {
alert("Flash app inited!");
appInited = true;
onFlashAppSizeChanged(width,height);
// remove the temporary swf container: tmp
document.body.removeChild(document.getElementById("tmp"));
}
function onFlashAppSizeChanged(width, height) {
flashApp.width = width + "px";
flashApp.height = height + "px";
}
但是现在从你的帖子来看,它并没有确切地建议应该做些什么来使swf适应html文件中的确切大小OK,在我上面的编辑中还有一些建议。希望这有帮助。我同意你在mxml和html中设置高度和宽度。但是默认情况下,我们不知道flex中按钮的大小,因此如果指定了默认按钮,如何知道其高度和宽度,以及如何在html中设置?:-?您可以尝试从flex中的onCreationComplete方法中检索按钮的大小(宽度/高度),并将其传递给javascript(作为参数沿flashAppInited方法传递)。通过这种方式,javascript端将收到关于按钮宽度的通知,并可以调整swf对象的大小,使其具有完全相同的大小。K..你能告诉我如何检索它的任何链接吗..顺便说一下,我看到了你的网站。虽然它不起作用,但已经很酷了..我已经更新了答案,基于此,您可以随时将flex按钮的大小发送到js端。也更新了样本(如果你想尝试的话)。目前为止运气好吗?如果您需要进一步指导,请告诉我+关于在flex和javascript之间使用通信的问题。
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="100">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="400" height="100" id="myMovieName"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<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"/>
<!-- the embed tag does not have href attribute -->
<embed width="400" height="100"
src="/media/players/testsound.swf"
flashvars="soundUrl=/media/players/music.mp3"
quality="high" bgcolor="#FFFFFF"
name="myMovieName" loop="false" align="middle"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
<mx:Script>
<![CDATA[
import mx.core.SoundAsset;
[Embed('/media/players/music.mp3')]
private var _sound:Class;
public var snd:SoundAsset = new _sound() as SoundAsset;
public var sndChannel:SoundChannel;
public function playSound():void {
sndChannel=snd.play();
}
]]>
</mx:Script>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
width="1" height="1" backgroundColor="#bee3f6"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
creationComplete="onCreationComplete()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
//This method will change the button's label ==> width.
public function sayWhat():void {
var _date:Date = new Date();
extButton.label = "It's " + (_date.getHours() + 1) + ":" + _date.getMinutes() +
((_date.getMilliseconds() % 2) == 0 ? ". nice." : ". very tired.");
}
public function onCreationComplete():void {
// binds this.sayWhat to the external interface, so when from
// javascript is called the compiled swf object's sayWhat function,
// it will be transferred to this.sayWhat.
ExternalInterface.addCallback("sayWhat", sayWhat);
// set the flash application's size to be exact the button's size.
this.width = extButton.width;
this.height = extButton.height;
try
{
// The js function: onFlashAppInited(width, height);
// The next line tells the external interface (the parent application:
// browser window), that this application has finished loading, its
// ready to be used.
// We're passing the button's width and height as parameters
// In js there has to be a global method with this name.
ExternalInterface.call("onFlashAppInited", extButton.width, extButton.height);
}
catch (e:Error)
{
trace(e.message + "\n" + e.getStackTrace(), e.name);
}
}
protected function onButtonUpdateComplete(event:FlexEvent):void
{
// if the button's size has changed, we notify the javascript to set the
// correct size to the object tag too.
if ((this.width != extButton.width) || (this.height != extButton.height))
{
// set the application size
this.width = extButton.width;
this.height = extButton.height;
// notify the js about the change
ExternalInterface.call("onFlashAppSizeChanged", this.width, this.height);
}
}
]]>
</mx:Script>
<mx:Button id="extButton" label="Do something!" updateComplete="onButtonUpdateComplete(event)" />
</mx:Application>
function onFlashAppInited(width, height) {
alert("Flash app inited!");
appInited = true;
onFlashAppSizeChanged(width,height);
// remove the temporary swf container: tmp
document.body.removeChild(document.getElementById("tmp"));
}
function onFlashAppSizeChanged(width, height) {
flashApp.width = width + "px";
flashApp.height = height + "px";
}