• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

URLloader error handling

New Here ,
Oct 27, 2011 Oct 27, 2011

Copy link to clipboard

Copied

I'm working on a game, that loads up external text files to create maps. There is a error if the player moves out of bounds, and there is no map to load. All I need is a sort of check to see if the text file actually exists, before loading it. Can anyone help me?

TOPICS
ActionScript

Views

2.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2011 Oct 27, 2011

Copy link to clipboard

Copied

you can use the ioerrorevent of your urlloader to capture the error and take appropriate steps:

import flash.events.IOErrorEvent;

yourURLLoader.addEventListener(IOErrorEvent.IO_ERROR,f);

function f(e:IOErrorEvent):void{

//do whatever

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2011 Oct 27, 2011

Copy link to clipboard

Copied

Thanks, thats pretty helpful, though I suppose I should be more specific. If no map exists, I want to send the player back to the previous map, or not have him move at all. Let me include some code to show what I'm currently doing.

function MoveWest():void //Also have a function for each direction, but I'll just use the West function for example.

                    {

 

                              worldX--;

                              startX = stage.stageWidth - 32;

                              startY = myPlayer.y;

                              loadMap()

 

                    }

function loadMap():void

                    {

                              DestroyMap(); //In case this isn't self explainatory, this removes the previous map from the stage.

                              //Layer 1

                              mapLoader = new URLLoader();

                              mapLoader.addEventListener(Event.COMPLETE, onmapLoad);

                              mapLoader.addEventListener(IOErrorEvent.IO_ERROR,error1);

                              mapLoader.load(new URLRequest("Maps/L1/"+worldX+","+worldY+".txt"));

                              //Layer 2

                              mapLoader2 = new URLLoader();

                              mapLoader2.addEventListener(Event.COMPLETE, onmapLoad2);

                              mapLoader2.addEventListener(IOErrorEvent.IO_ERROR,error2);

                              mapLoader2.load(new URLRequest("Maps/L2/"+worldX+","+worldY+".txt"));

                    }

                    function error1(e:IOErrorEvent):void

                    {

                              //do whatever

                              trace("Something went wrong!");

                    }

                    function error2(e:IOErrorEvent):void

                    {

                              //do whatever

                              trace("Something went wrong!");

                    }

So basicly, I want something I can put into the "Move" functions, where if said text file doesn't exist, treat that direction as a solid wall.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2011 Oct 27, 2011

Copy link to clipboard

Copied

LATEST

i don't know what your 2 layers are but here's how you would load the previous map if you had one map/layer:

var previousMap:String;

function MoveWest():void //Also have a function for each direction, but I'll just use the West function for example.

                    {

 

                              worldX--;

                              startX = stage.stageWidth - 32;

                              startY = myPlayer.y;

                              loadMap()

 

                    }

function loadMap(s:String=null):void

                    {

                              DestroyMap(); //In case this isn't self explainatory, this removes the previous map from the stage.

                              //Layer 1

                              mapLoader = new URLLoader();

                              mapLoader.addEventListener(Event.COMPLETE, onmapLoad);

                              mapLoader.addEventListener(IOErrorEvent.IO_ERROR,error 1);

                              mapLoader.load(new URLRequest("Maps/L1/"+worldX+","+worldY+".txt"));

                              //Layer 2

                              mapLoader2 = new URLLoader();

                              mapLoader2.addEventListener(Event.COMPLETE, onmapLoad2);

                              mapLoader2.addEventListener(IOErrorEvent.IO_ERROR,erro r2);

if(!s){

                              mapLoader2.load(new URLRequest("Maps/L2/"+worldX+","+worldY+".txt"));

} else {

mapLoader2.load(new URLRequest(s));

}

                    }

                    function error1(e:IOErrorEvent):void

                    {

                              //do whatever

                              trace("Something went wrong!");

                    }

                    function error2(e:IOErrorEvent):void

                    {

                             

loadMap(previousMap);

                    }

function onmapLoad2(e:Event):void{

previousMap = "Maps/L2/"+worldX+","+worldY+".txt"; 

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines