Home  >  Article  >  Web Front-end  >  How does js determine whether the flash swf file is loaded_javascript skills

How does js determine whether the flash swf file is loaded_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:39:341282browse

How does js determine whether flash has been loaded?

How do we call back a js function we set when the flash is loaded?

This problem has been bothering me for a long time. Until today, after consulting a very awesome person, I suddenly felt it!

Haha, maybe this problem is not a problem to you, but for me, it is indeed a problem, because I never know how to judge whether the swf file has been loaded?

In the past, I only knew about img.onload and so on.

Okay, let’s get down to business, how do we judge whether a flash has been loaded?

Yes, it is polling, and then determines whether a certain method of flash can run normally?

The example is as follows (pseudocode):

(function () { 
var flash = 网页上某个flash对象。 

var interval = setInterval(function () { 
try { 
if(flash.IsPlaying()) { //轮询flash的某个方法即可 
callBack && callBack.call(flash, args); //回调函数 
clearInterval(interval); 
} 
} catch (ex) { 

} 
}, 1000); 

var callBack = function () { 
alert('loaded'); 
} 
})();

//In specific use, when the flash is placed in the function closure of setInterval or setTimeout, it may be due to JavaScript single-threaded issues that the flash cannot call IsPlaying and other flash player functions or the call results are unequal. There is a temporary situation here. The solution is that we can read the TotalFrames attribute of flash in the polling function. If we read it, we can think that the flash has been completely loaded into the page! ! !

After testing, it is indeed feasible, but there may be a 1-2 second delay.

/////////////If there is anything wrong, please correct me! ! ! ! ! ! ! ! ! //////////////

/*Attached is a list of js methods that can control Flash Player*/

Play() ------------------------------------- Play animation
StopPlay()------------------------------------Stop animation
IsPlaying()---------------------------------- Whether the animation is playing
GotoFrame(frame_number)---------------- Jump to a certain frame
TotalFrames()--------------------------------- Get the total number of animation frames
CurrentFrame()------------------------------Returns the frame number of the current animation -1
Rewind()----------------------------------------returns the animation to the first frame
SetZoomRect(left,top,right,buttom)-------Enlarge the specified area
Zoom(percent)---------------------------------Change animation size
Pan(x_position,y_position,unit)------------makes the animation translate in the x, y direction
PercentLoaded()--------------------------Returns the percentage of the animation being loaded
LoadMovie(level_number,path)---------- Load animation
TGotoFrame(movie_clip,frame_number)- movie_clip jumps to the specified frame number
TGotoLabel(movie_clip,label_name)------ movie_clip jumps to the specified label
TCurrentFrame(movie_clip)--------------- Returns the current frame of movie_clip -1
TCurrentLabel(movie_clip)-----------------Return the current label of movie_clip
TPlay(movie_clip)--------------------------Play movie_clip
TStopPlay(movie_clip)----------------------Stop the playback of movie_clip
GetVariable(variable_name)-----------------Get variable
SetVariable(variable_name,value)----------Variable assignment
TCallFrame(movie_clip,frame_number)---call action on the specified frame
TCallLabel(movie_clip,label)----------------call the action on the specified label
TGetProperty(movie_clip,property)--------Get the specified property of movie_clip
TSetProperty(movie_clip,property,number)-Set the specified property of movie_clip

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn