开发者

Change flash src with jquery?

Hi I have a flash menu showing a few links, but when the user is logged in I want to change the menu from menu1 to menu2 ... so that it will display "My Account" rather than "Signup"

The code below is for my flash:

开发者_如何学C<div id="menu"> 
 <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="825" height="69" id="menu1" align="middle">
 <param name="allowScriptAccess" value="sameDomain" />
 <param name="allowFullScreen" value="false" />
 <param name="movie" value="menu1.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /> <embed src="menu1.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="825" height="69" name="menu1" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
 </object>
 </div>

Php:

if (loggedin())
 {

  echo '<script type="text/javascript">
   CHANGE FLASH LINK HERE
   </script>';  


 }

Could this be done without having to write all the above code out again?

Thanks :)


Use .attr():

$(document).ready(function() {
    $("#menu > object > embed").attr("src", "new link");
});


If loggedin() is a load-time check done on the server-side, why not simply change the output from PHP?

<div id="menu"> 
    <?php if (loggedin()) { ?>
        <object ...> ...
            <param name="movie" value="menu2.swf" /> ...
        </object>
    <?php } else { ?>
        <object ...> ...
            <param name="movie" value="menu1.swf" /> ...
        </object>
    <?php } ?>
</div>

If you really must do it from script then yes, you should create a new Flash object (by innerHTML or DOM methods, or getting a script like SWFObject to do it for you). Changing the source of a plugin object is not something you can do reliably cross-browser (especially IE).

It might be better to include both menus on the page and just use display to hide one of them.

It would almost certainly be better not to use Flash menus, which tend to be a usability, accessibility and SEO disaster. You've got a lot of animation possibilities built into jQuery and HTML5/CSS3/etc is increasingly capable of pretty effects. Flash menus are so 2003.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜