views:

175

answers:

1

I am trying to load my png file to my application. here is the code

var map:mapLoader = new mapLoader();
map.loadMap("tile.png");

Then here is my file that loads it. it throws the error right when it gets to

loader.load(new URLRequest(currentMap));

if I comment it out. then the error goes away. below is the code in its entirety

package {
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.net.*;
    import flash.events.*;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Sprite;    

    public class mapLoader extends Sprite{

        private var currentMap:String;
        private var loader:Loader;
        private var xmlLoader:URLLoader;
        private var worldRows:Number = 100;
        private var worldCols:Number = 100;
        public var world:Array;
        public var mapTile:BitmapData;
        public var arry:Array = new Array();

        public function mapLoader():void
        {
            // the output window width and height in pixels

            worldCols=100;      
            worldRows=100;          


            world = new Array();
        }

        public function loadMap(mapName:String = "empty"):void
        {
            currentMap = mapName;

            if(currentMap != "empty")
            {
                //load in tile sheet image
                loader = new Loader();
                loader.contentLoaderInfo.addEventListener(Event.INIT,tilesLoadInit);
                loader.load(new URLRequest(currentMap));
            }
        }//End MapLoader

         private function tilesLoadInit (e:Event):void {
               mapTile = Bitmap(loader.content).bitmapData;

         }
        }
}

I am getting the following error

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
A: 

The code is loading an external (ie. not embedded) asset, "tile.png", which should be placed near your HTML page or SWF file depending on how you play it.

As a rule, the path of these external elements is relative to the "top level container":

  • the HTML page if you're doing a website,
  • the SWF file itself if you are playing it standalone (as an EXE or when you run the project from FlashDevelop).

This is something to be very careful about and a source of confusion for beginners.

Philippe