开发者

How does a browser load a flash file? (swf)

How does the browser load flash files? Do they load progressively, or does the browser wait until the entire flash file is loa开发者_运维问答ded before displaying it?

The reason is I have a tiny clip that is extremely high in quality, only a few seconds long, but it's over 4 mb.

Will the user have to wait until all 4 mb is loaded before viewing? Or does it load as the user watches it?

I didn't do anything fancy, I just imported a .flv into Flash, and exported as a .swf.

Thank you in advanced


There are many parts to loading a flash file, and more generically, an HTML page.

I'm going to start from the top with the HTML page, and I urge others to correct any mistakes I may have made.

Loading a Page

When an HTML page is received, the browser parses it into the Document Object Model (DOM) so that it has a programmatic representation of every element. Browsers iterate over every node in the DOM tree and populate it as-needed.

For most nodes this is simply creating a new DOM element like a div, p, or a; however some content requires loading or replacement.

form elements (input, select, button, textarea) are replaced with the browser-specific representation of those form fields.

link elements used as stylesheets are asynchronously loaded. The DOM continues to parse the page as the external resource is being loaded.

script elements on the other hand, are synchronously loaded. The DOM is unable to continue parsing the tree until the script has finished loading and executing, with exceptions for if the loading failed or the execution had an error.

img elements are asynchronously loaded, but allow for the onload callback to determine when they have finished loading. The DOM can't trigger the window's onload event until all img elements have finished loading (or failed).

Understanding the basic elements helps with understanding more involved elements like object, embed, and iframe, which are also replaced content.

Flash is typically embedded on a webpage using object, embed and iframe.

As far as I'm aware, object and embed elements react similarly so I will shortcut and say object from here on out.

There are distinct differences between loading flash in iframe and object elements.

The object element is very similar to a script element where the content must be successfully loaded and executed before the DOM can continue to be parsed.

The iframe element is very similar to an img element where the contents are loaded asynchronously, but a callback may be used to determine when the loading has finished (although I'm not sure about whether the callback is available for cross-domain requests).

Loading Flash

The previous section discusses just the HTML side of content loading. However, there are a number of nuances within flash that can severely affect the load time of a flash movie.

As I stated before, script elements must be fully loaded and executed before the DOM can continue being parsed. A similar effect is found within Flash files (even when included via an iframe). All resources embedded within the swf must be loaded before the swf can release its hold on the page loading progress.

If you've embedded a video directly into the timeline, the entire video must load before flash can be considered done with its initial execution.

If, instead, you chose to use an asynchronous callback to start loading an external resource that happened to be a video, and used an asynchronous loader to load the video, you wouldn't have to wait for the video to be finished loading before the rest of the page could be loaded; within flash, you'd still need to wait for the video to finish loading before beginning playback of the video.

Alternatively, there are a number of means within flash to either stream videos, or progressively load a video from a server, which would enable the video to be played without being finished loading. My experience with that particular aspect of flash is minimal, so I won't explain how it's done.

Using a library like swfobject allows the desired swf to be loaded asynchronously so that flash loading is non-blocking.

tl; dr:

Flash files may be loaded progressively depending on how you've structured your HTML, and what code is running in the swf.

You may want to look into swfobject


swf files are loaded progressively (hence loader bars, "50% loaded" messages and such).

Historically, Flash files are based on frames, and if the main timeline has multiple frames, they will be loaded and displayed in sequence, as soon as they are loaded, before the entire file is loaded. However, most Flash content nowadays is not constructed that way, and are more complex than a series of frames that are displayed in sequence. Video playback also adds complexity beyond the basic frame model, with video codecs, audio synch and such.

So the answer to the question "Do they load progressively, or does the browser wait until the entire flash file is loaded before displaying it?" is that they load progressively and are displayed before the entire swf files is loaded. But how this will effect how the users experience your video is hard to tell without seeing it or how it is constructed.


It will load the entire movie first. So make your video an external file that the movie loads when it runs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜