2011-05-22 59 views
0

我想知道如果它可能調整與JavaScript的Flash。我不能單獨更改flash對象中的任何代碼,我所擁有的僅僅是html,javascript和php。用Javascript調整Flash的大小?

繼承人是我迄今爲止的發現:

var changeMe = document.getElementById("content_embed"); 
    changeMe.height = yy; 
    changeMe.width = xx; 
    if (navigator.userAgent.toLowerCase().indexOf("safari")!=-1) { 
    var changemeObject = document.getElementById("content_object"); 
    changeMeObject.height = yy; 
    changeMeObject.width = xx; 
    } 
} 

內容是嵌入嵌入標籤和內容對象是在Flash對象標記。這在鉻(可能是Firefox)的作品,但不是即。 在Internet Explorer中出現錯誤:Unable to set value of the property 'height': object is null or undefined
以下是我一直使用的示例頁面:http://futuregamespc.com/behind/Popup/ 任何人都可以幫忙嗎?謝謝你們,你們讓這個網站真棒。

+0

嘗試使用jquery將所有那些瀏覽器特定的代碼抽象出來。 – 2011-05-22 03:21:06

+0

http://futuregamespc.com/behind/Popup/index2.html這樣做,它不能在鉻或Internet Explorer中工作,並足夠奇怪,它不會返回任何錯誤,只是不起作用。 – Matt 2011-05-22 03:32:38

回答

1

是的,這是可能的。

但是,只要您在網站上顯示Flash,請使用swfobject

Its a lightweight JavaScript library that allows you to integrate swf in a cross browser friendly way to your website.

下面給出的是呼叫的樣品swfobject的

var flashvars = {}; 
var params = {}; 
var attributes = {}; 
var width="300"; 
var height="120"; 

swfobject.embedSWF("myContent.swf", "myContent", width, height, "9.0.0","expressInstall.swf", flashvars, params, attributes); 

正如你所看到的,heightwidth傳遞的參數。
Read swfobject documentation瞭解更多詳情。

更新:這是在Adobe網站本身的another good write up on using swfobject

+1

我不確定這是否符合運營商尋找的動態標準。他希望在swf被加載到dom後調整它的大小。使用此建議,他必須銷燬並重新創建該對象,如果需要在調整大小後保留在同一位置,可能會出現問題 – 2011-05-22 03:47:08

+0

感謝這正是我所需要的。我可以在沒有太多變化的情況下將它用於所有的swf文件。我想要一個可以保存Flash文件狀態的解決方案,並且這個工作非常完美。 – Matt 2011-05-22 18:01:47