views:

158

answers:

1

I have some AS2 code that opens a SWF file through an HttpHandler.

I'm trying to get the program to recognize when a requested file is missing.

My first attempt involved using LoadVars and "load", and only calling loadMovie if the file successfully loaded (found the technique somewhere out here). However, I found that the ProcessRequest function in the HttpHandler was getting called twice when the file does exist. Makes sense - once for load, once for loadMovie.

Now I'm using MovieClipLoader instead (also found this technique out here). This way does call ProcessRequest only once whether or not the file is found. But my problem is that the onLoadError function is only working when I give it a bad URL. If I give it a good URL that passes a bad filename to the handler, the handler throws an error, but my onLoadError function doesn't seem to recognize that there's a problem - I just get a blank area where the error message should be showing up.

Here's the relevant AS2 code:

function CheckFileExists(inFile) {

    var mclListener:Object = new Object();
    mclListener.onLoadError = function(target_mc:MovieClip, err:String){
         if(err=="URLNotFound")
         {
             target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
             target_mc.error_txt.autoSize = "left";
             target_mc.error_txt.text = "URL not found: \n\t" + target_mc._url;
         }
         else //I would expect this block to handle the error, since the URL is good.
         {
             target_mc.createTextField("error_txt", 1, 0, 0, 100, 20);
             target_mc.error_txt.autoSize = "left";
             target_mc.error_txt.text = "some other problem: \n\t" + target_mc._url;
         }
    }

    var mcl:MovieClipLoader = new MovieClipLoader();
    mcl.addListener(mclListener);
    var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
    mcl.loadClip(inFile, mc);
}

Little help?

+1  A: 

How is your server function throwing an error? Make sure it returns an actual HTTP error code like 404 or 503 or something. If it's returning HTTP status code 200 with an error as a text message, then Flash does not know this is an error. It just sees the status 200 and thinks the load is fine, and attempts to load the data as a flash movie.

davr
A catch block is getting a "Could not find file..." exception, but I'm not doing anything with it. For some reason this is sufficient for triggering the error in the AS2 onLoadError function with a bad URL, but not for a bad filename.My error handling skills are lacking. How would I go about returning the HTTP error code I want? Do I need to write that to HttpContext.Response somehow?Thanks for the help.
Jim Givitis
This seems to do the trick (in the catch block):context.Response.StatusCode = 404;Is there a pretty way to identify the error type coming into the "catch(Exception ex)" and set the status code accordingly?
Jim Givitis
Never mind.. I should probably figure that out on my own. Thanks again for the help, davr. I tried to "vote up" your answer, but it looks like I can't do that w/o a 15 reputation (I'm new here). Hopefully someone else can vote it up, as your answer did solve my problem.
Jim Givitis
Yeah, I don't know .NET, so I can't help you with the specifics of that code, I was just describing what seemed like was the general cause of the problem
davr