2010-12-04 89 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