Jump to content
GreenSock

friendlygiraffe

onError: More detail

Recommended Posts

Hi, is it possible to get a more detailed report on ErrorHanding?

 

var queue:LoaderMax = new LoaderMax({name: "mainQueue", onComplete: completeHandler, onError: errorHandler});

private function displayError(myText:String):void
 {
  errorText.text += myText + "\n\n";
 }

outputs:

 

error occured in:

ImageLoader 'myimage' (image.jpg)

It's impossible to work out whether it's 404, or Crossdomain policy etc ...

 

Thanks

Link to comment
Share on other sites

I didn't see in your code anywhere that you're handling the error. Could you post your errorHandler() method?

 

The LoaderEvent that gets passed to the error handler function has a "text" property that will be the actual error text, plus if there is a raw Error or Event that Flash throws, it will be attached to the "data" property of the LoaderEvent. So you should be able to get all the info Flash provides. And don't forget that every loader has an httpStatus property you can check (of course a LoaderMax instance itself doesn't have one because it can contain many loaders, but you could getChildren() and loop through those if you want to check them).

Link to comment
Share on other sites

Thanks for your reply Jack

Sorry I missed a couple of functions. Here is my full code:

Is it possible to get the info of ANY kind of error to display in my textField. eg: httpStatus, everything from the 'data' object

 

public function LoaderWheel(myRoot:MovieClip, myLM)
 {

  TweenMax.to(loadTxt, 0, {tint: 0x000000});

  this.myRoot = myRoot;

  stageHeight = myRoot.stage.stageHeight;
  stageWidth = myRoot.stage.stageWidth;

  this.x = stageWidth / 2;
  this.y = stageHeight / 2;

  var queue:LoaderMax = new LoaderMax({name: "mainQueue", integrateProgress: true, onComplete: completeHandler, onProgress: progressHandler, onError: errorHandler});
  queue.append(myLM);
  queue.load();

 }

 private function progressHandler(event:LoaderEvent):void
 {
  var per:Number = Math.round(event.target.progress * 100);
  if (per < 100)
  {
   loadTxt.text = per + "%";
  }
 }

 private function completeHandler(e:LoaderEvent):void
 {
  TweenMax.to(this, 0.5, {autoAlpha: 0, onComplete: init})
 }

 private function displayError(myText:String):void
 {

  if (errorText == null)
  {
   errorText = new TextField();
   errorText.background = true;
   errorText.border = true;
   errorText.backgroundColor = 0xFFFFFF;
   errorText.multiline = true;
   errorText.wordWrap = true;
   errorText.selectable = true;
   errorText.width = stageWidth;
   errorText.height = stageHeight / 1.5;
   errorText.alpha = 0.6;
   errorText.text ="error occured in:\n" ;
   myRoot.addChild(errorText);
  }
  errorText.appendText(myText + "\n\n");
  errorText.autoSize = "left";
  myRoot.stage.focus = errorText;
  errorText.setSelection(0, errorText.text.length);
 }

 private function errorHandler(event:LoaderEvent):void
 {
  trace("error occured in " + event.target);
  displayError(String(event.target));
 }

 private function init():void
 {
  var Loaded:Event = new Event(Event.COMPLETE);
  dispatchEvent(Loaded);
 }

Link to comment
Share on other sites

It'd be easy to get the "text" from an error, yes:

private function errorHandler(event:LoaderEvent):void  {
  trace(event.text);
  displayError(event.text);
}

 

Which should be all you need, quite frankly. Displaying the "data" is more difficult because it could be a different type of object based on the loader. It could be a NetStreamEvent, an ErrorEvent, or a number of other things. You could just use toString() or cast it to a String() yourself which would probably give you what you need. But again, I doubt you'll even need the "data" because the "text" should provide some details.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×