Determine whether a flash file exists

Source: Internet
Author: User

CopyCode The Code is as follows: var exist = new loadvars ();
Exist. onload = function (SUCCESS ){
If (! Success ){
Trace ("file does not exist ");
}
}
Exist. Load ("file name ");

This code should be said to mislead us. The onload event refers to the Code executed after the file is downloaded. If only the local file can be determined, because it does not need to be downloaded, it will be troublesome to judge the network file. If you want to judge an online movie, I'm sorry, you will not be notified of the existence of this movie until you download it.
so I thought that I should only judge whether the file exists, and only check whether it has any content, that is, getbytestotal (), to get the total number of bytes of the file, if the current load operation is not performed or the load operation has not started, this method returns undefined. If you cannot determine the total number of bytes (for example, if the download has started but the server has not transmitted HTTP Content-Length), this method also returns undefined. So we can determine whether the file exists: copy Code the code is as follows: var exist = new loadvars ();
This. createemptymovieclip ("item_mc", this. getnexthighestdepth ();
item_mc.onenterframe = function () {
var total ready this.tar get. getbytestotal ();
If (INT (total)> 101) {
// Total = undefined is not used in this case, because it cannot be found, if the file does not exist, INT (total) = 101
Delete item_mc.onenterframe;
trace ("file exists");
trace (INT (total )); // return the total byte
}< BR >}< br> item_mc.target = exist;
exist. load ("file address");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.