简体   繁体   中英

How to correctly replay any flash .swf file using Javascript?

I am trying to replay a .swf flash file using javascript.Currently I am aware of two methods of doing this:

1) hide the element and show it again

2) select the DOM element of the swfobject and call .Rewind() and .Play()

http://jsfiddle.net/me2loveit2/4qth8/

//method one
    $('#objectID').hide();
    setTimeout(function(){
        $('#objectID').show();
    },10)
//Method 2
    document.getElementById('objectID').Rewind();
    document.getElementById('objectID').Play();

The problem with hide and show is that it sometimes flashes on the screen and is visually unappealing. And the problem with .Rewind() or .GotoFrame(0) and .Play() is that it only rewinds the main timeline.(notice only the second green block resets and animates)

I usually have no control or way to change anything within the flash, so I am trying to find a solution that does not involve editing the flash file.

Is there is a way to get the name of all the movie clips that are in the swf using Javascript?. Then I could rewind them individually using .TGotoFrame('movieclip',0)

Can I trigger the same events that hide and show do without actually hiding and showing the element? (How?)

Or is there a better way to replay?

You could also restart it without the 10ms delay by using swfobject to rewrite the swf tag:

$(document).on('click','#replay3',function(){
    swfobject.embedSWF("http://philipp.werminghausen.us/testing/test.swf", 'replace', 275, 200, "9", null, {}, params, {}, function (res) {});

});

Example:

http://jsfiddle.net/5jqW4/

I found another way to do it as well by removing and reinserting one of the <param> tags. This way I don't need to re-create the object:

http://jsfiddle.net/me2loveit2/5jqW4/10/

var param = $('#swf_movie').children().first().detach();
$('#swf_movie').append(param);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM