您應該在主要的mxml中指定Application
的寬度和高度,即使它包含一個可點擊的圖像!
如果您想您的網頁,我們的width: 400px
和height: 100px
柔性圖像(按鈕?),那麼你的Application
標籤必須是這樣的:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="100">
而儘管如此,在你的HTML你應該有你的兩object
和embed
標籤具有相同的width
和height
,您應該爲您的embed
標籤的屬性指定一個值,例如:align="middle"
。
你object
標籤應該類似於
<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>
其他 哪裏是你的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>
如果您想指定從HTML你的MP3的路徑,你可能看this post for reference。
更新2
設置HTML object
的寬度和高度根據你的Flex按鈕的大小,你應該作如下更新您的應用程序MXML代碼:
<?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>
注意,最初這個應用程序只有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";
}
從您的文章
我同意你有關在mxml和html中設置高度和寬度。但默認情況下,我們不知道Flex中按鈕的大小,所以如果指定了默認按鈕,如何知道它的高度和寬度以及如何在html中設置..? – Naveen 2011-04-19 17:04:04
: - ?你可以嘗試從flex的onCreationComplete方法中檢索按鈕的大小(寬度/高度),並將其傳遞給JavaScript(沿着flashAppInited方法作爲參數)。通過這種方式,JavaScript端會收到關於按鈕寬度的通知,並且可以調整swf對象的大小以獲得完全相同的大小。 – rekaszeru 2011-04-19 17:06:46
K..Can你讓我知道如何檢索它的任何鏈接..順便說一下,我看到你的網站。雖然它的功能它已經很酷.. – Naveen 2011-04-19 17:21:29