2010-12-04 92 views
0

我在ie中克隆了一個flash,並在其中更改了一些變量。這是功能:在IE中克隆對象(.clone)時遇到的問題

$(function() { 
    $("select[name='variation3']").live('change', function() { 
    var player = $(this).parent().parent().parent().find('object:first'); 
    if(player.length == 0) 
     player = $(this).parent().parent().parent().find('.player_not_single, .player_singele'); 

    var $param = player.find("param[name='flashvars']"); 
    var path = player.closest('.post1').attr('data-demo'); 

    //$param.attr('value', $param.attr('value').replace(/soundFile=([^&]+)/, 'soundFile=' + path + $(this).find(':selected').val() + '.mp3')); 

    $param.attr("value", function(i,v) { return v.replace(/soundFile=([^&]+)/, 'soundFile=' + path + $(this).find(':selected').val() + '.mp3'); }); 

    var new_player = player.clone(); 
    new_player.insertBefore(player); 
    player.remove(); 
    }); 
}); 

在FF它工作正常,但inIE它使問題。這是克隆之前的代碼:

<object name="audioplayer_1" width="270" height="24" id="audioplayer_1" 
     classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
     style="outline-style:none; outline-color:invert; outline-width:medium;"> 
    <param name="bgcolor" value="#FFFFFF"/> 
    <param name="wmode" value="transparent"/> 
    <param name="menu" value="false"/> 
    <param name="flashvars" value="animation=no&encode=no&initialvolume=60&remaining=no&noinfo=yes&buffer=3&checkpolicy=no&rtl=no&bg=363635&text=333333&leftbg=4f4f4f&lefticon=787171&volslider=71bced&voltrack=777987&rightbg=4d4d4d&rightbghover=66a7d9&righticon=969696&righticonhover=000000&track=c2bebe&loader=5f91f5&border=000000&tracker=90b7d1&skip=b3b3b3&soundFile=http%3A%2F%2Fwww.gameaudio.net%2Fprelisten%2Fanotherworld%2Ffulledit.mp3&playerID=audioplayer_1"/> 
    <param name="movie" value="http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1"/> 
</object> 

而這種代碼克隆後:

<object name="audioplayer_1" width="270" height="24" id="audioplayer_1" 
     classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
     style="outline-style:none; outline-color:invert; outline-width:medium;"> 
    <param name="_cx" value="7143"/> 
    <param name="_cy" value="635"/> 
    <param name="FlashVars" value=""/> 
    <param name="Movie" value="http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1"/> 
    <param name="WMode" value="Transparent"/> 
    <param name="BGColor" value="FFFFFF"/> 
    [...] 
</object> 

這是不一樣的。在部分是,但不是全部,尤其是。最重要的部分不見了。 什麼可能是錯誤?

UPDATE: 這是我當前的代碼: 「功能embedAudioPlayer(replaceElemIdStr,AUDIOFILE){

swfobject.embedSWF( 
    "http://www.gameaudio.net/wp-content/plugins/audio-player/assets /player.swf?ver=2.0.4.1", 
    replaceElemIdStr, 
    width, 
    height, 
    "9.0.115", 
    "expressInstall.swf", 
    { 
     soundFile: audioFile 
    }); 

}

$(函數(){

$(「選擇[ ('change',function(){

player = $(this).parent().parent().parent().find('.player_not_single, .player_singele'); 

var $param = player.find("param[name='flashvars']"); 
var path = player.closest('.post1').attr('data-demo'); 
var audioFile = path + $(this).find(':selected').val() + '.mp3'; 
var uniqueId = 'audio-' + +new Date; 
player.replaceWith('<div id="+uniqueId+"/>'); 
embedAudioPlayer(uniqueId, audioFile); 

}); '

function embedAudioPlayer(replaceElemIdStr,audioFile)var swfobject = audioplayer_swfobject;
swfobject.embedSWF( 「http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1」, replaceElemIdStr, 250, 50, 「9.0.115」, 「expressInstall.swf」, { soundFile:audioFile }); }

$(函數(){

$( 「選擇[名稱= 'variation3']」)活( '變更',函數(){

player = $(this).parent().parent().parent().find('.player_not_single, .player_singele'); 

var $param = player.find("param[name='flashvars']"); 
var path = player.closest('.post1').attr('data-demo'); 
var audioFile = path + $(this).find(':selected').val() + '.mp3'; 
var uniqueId = 'audio-' + +new Date; 
player.replaceWith('<div id="+uniqueId+"/>'); 
embedAudioPlayer(uniqueId, audioFile); 

。});

更新:

` 功能embedAudioPlayer(replaceElemIdStr,AUDIOFILE){ VAR swfobject的= audioplayer_swfobject;
swfobject.embedSWF( 「http://www.gameaudio.net/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1」, replaceElemIdStr, 250, 50, 「9.0.115」, 「expressInstall.swf」, { soundFile:audioFile }); }

$(函數(){

$( 「選擇[名稱= 'variation3']」)。生活( '變',函數(){

player = $(this).parent().parent().parent().find('.player_not_single, .player_singele'); 

var $param = player.find("param[name='flashvars']"); 
var path = player.closest('.post1').attr('data-demo'); 
var audioFile = path + $(this).find(':selected').val() + '.mp3'; 
var uniqueId = 'audio-' + +new Date; 
player.replaceWith('<div id="+uniqueId+"/>'); 
embedAudioPlayer(uniqueId, audioFile); 

});`

+0

你會發佈一個網址到這個問題的示例頁面嗎? – 2010-12-08 01:08:05

回答

1

Firefox和一切,但IE使用Netscape Plugin Application Programming Interface (NPAPI)爲Flash。 Firefox(等)使用param元素,但IE從屬性讀取。這是煩人的指定一切兩次,但that's what you have to do,除非你使用類似swfobject這樣做爲你(強烈推薦)。

更新基於使用SWFObject:

聽起來你基本上是試圖重新實現swfobject.embedSWF使用jQuery.clone。我相信它可以工作,但我建議你堅持swfobject的Flash嵌入和jQuery的DOM。我會用以下結構:

function embedAudioPlayer(replaceElemIdStr, audioFile) { 
    // customize these options for the audio player you're using 
    swfobject.embedSWF(
     "yourplayer.swf", 
     replaceElemIdStr, 
     width, 
     height, 
     "9.0.115", 
     "expressInstall.swf", 
     { 
      soundFile = audioFile 
     }); 
} 

$("select[name='variation3']").live('change', function() { 
    // ... 
    var audioFile = path + $(this).find(':selected').val() + '.mp3'; 
    var uniqueId = 'audio-' + +new Date; 
    player.replaceWith('<div id="+uniqueId+"/>'); 
    embedAudioPlayer(uniqueId, audioFile); 
}); 
  1. 創建embedAudioPlayer功能,並使用它的一切都在初始頁面加載和響應頁面事件。
  2. 響應頁面事件時,使用jQuery來確定應該創建新音頻播放器的soundFile url和destination元素。
+0

使用swf對象。它生成上面的第一個代碼。在flash被克隆後,swf對象似乎沒有被執行。我可以在我的功能結束時調用它嗎? – Cindy 2010-12-04 21:21:37