How does js determine if the flash SWF file is loaded

  • 2020-03-30 03:43:35
  • OfStack

How does js determine if flash is loaded?

How do we call back a js function we set up when flash is finished loading?

This problem has been bothering me for a long time, until today, after consulting a very good B character, suddenly came to feel!

Well, maybe this isn't a problem for you, but it is for me, because I don't know how to tell if the SWF file is loaded or not.

It used to be img.onload and so on.

Okay, so how do we know if a flash is loaded or not?

That's right, polling to see if a flash method is working?

Here's an example (pseudocode) :


(function () { 
var flash =  On the web flash Object.  

var interval = setInterval(function () { 
try { 
if(flash.IsPlaying()) { //Poll a method of flash
callBack && callBack.call(flash, args); //The callback function
clearInterval(interval); 
} 
} catch (ex) { 

} 
}, 1000); 

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

/ / concrete application, the flash into the setInterval and setTimeout function closures, may be because JavaScript single-threaded problem, cause flash player such as flash cannot call IsPlaying function calls the results or unequal status, there is a temporary solution, we can read in polling function reads the flash TotalFrames attributes, read, we can think flash is fully loaded into the page!!!!!!

It works, but there may be a delay of 1-2 seconds.

///////////// /////// //////////////

Play () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the animation
StopPlay () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - to stop the animation
IsPlaying () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- whether the animation is played
GotoFrame(frame_number)-- jump to a frame
TotalFrames () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - for the animation to the total number of frames
CurrentFrame () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- returns the current animation where the frame number 1
Rewind () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- make the animation to return to the first frame
SetZoomRect(left,top,right,buttom)-- zooms in on the specified area
Zoom(percent)-- change the size of the animation
Pan (x_position y_position, unit) -- -- -- -- -- -- -- -- -- -- -- -- make the animation in the x, y direction in translation
PercentLoaded () -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- returned animation is the percentage of the load
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) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- back movie_clip current frame 1
TCurrentLabel (movie_clip) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- back movie_clip current label
TPlay (movie_clip) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- play movie_clip
TStopPlay (movie_clip) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- stop movie_clip play
GetVariable(variable_name)-- gets the variable
SetVariable(variable_name,value)-- variable assignment
TCallFrame(movie_clip,frame_number)-- call specifies the action on the frame
TCallLabel (movie_clip, label) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - call the action specified on the label
TGetProperty(movie_clip,property)-- gets the specified property of movie_clip
TSetProperty(movie_clip,property,number)- sets the specified property of movie_clip


Related articles: