dist/melonjs.js
function preloadTMX(tmxData, onload, onerror) {
         function addToTMXList(data) {
           // set the TMX content
           tmxList[tmxData.name] = data; // add the tmx to the levelDirector

           if (tmxData.type === "tmx") {
             me.levelDirector.addTMXLevel(tmxData.name);
           }
         } //if the data is in the tmxData object, don't get it via a XMLHTTPRequest


         if (tmxData.data) {
           addToTMXList(tmxData.data);
           onload();
           return;
         }

         var xmlhttp = new XMLHttpRequest(); // check the data format ('tmx', 'json')

         var format = me.utils.file.getExtension(tmxData.src);

         if (xmlhttp.overrideMimeType) {
           if (format === "json") {
             xmlhttp.overrideMimeType("application/json");
           } else {
             xmlhttp.overrideMimeType("text/xml");
           }
         }

         xmlhttp.open("GET", tmxData.src + api.nocache, true);
         xmlhttp.withCredentials = me.loader.withCredentials; // set the callbacks

         xmlhttp.ontimeout = onerror;

         xmlhttp.onreadystatechange = function () {
           if (xmlhttp.readyState === 4) {
             // status = 0 when file protocol is used, or cross-domain origin,
             // (With Chrome use "--allow-file-access-from-files --disable-web-security")
             if (xmlhttp.status === 200 || xmlhttp.status === 0 && xmlhttp.responseText) {
               var result = null; // parse response

               switch (format) {
                 case "xml":
                 case "tmx":
                 case "tsx":
                   // ie9 does not fully implement the responseXML
                   if (me.device.ua.match(/msie/i) || !xmlhttp.responseXML) {
                     if (window.DOMParser) {
                       // manually create the XML DOM
                       result = new DOMParser().parseFromString(xmlhttp.responseText, "text/xml");
                     } else {
                       throw new Error("XML file format loading not supported, use the JSON file format instead");
                     }
                   } else {
                     result = xmlhttp.responseXML;
                   } // converts to a JS object


                   var data = me.TMXUtils.parse(result);

                   switch (format) {
                     case "tmx":
                       result = data.map;
                       break;

                     case "tsx":
                       result = data.tilesets[0];
                       break;
                   }

                   break;

                 case "json":
                   result = JSON.parse(xmlhttp.responseText);
                   break;

                 default:
                   throw new Error("TMX file format " + format + "not supported !");
               } //set the TMX content


               addToTMXList(result); // fire the callback

               onload();
             } else {
               onerror(tmxData.name);
             }
           }
         }; // send the request


         xmlhttp.send();
       }
function preloadTMX(tmxData, onload, onerror) {
         function addToTMXList(data) {
           // set the TMX content
           tmxList[tmxData.name] = data; // add the tmx to the levelDirector

           if (tmxData.type === "tmx") {
             me.levelDirector.addTMXLevel(tmxData.name);
           }
         } //if the data is in the tmxData object, don't get it via a XMLHTTPRequest


         if (tmxData.data) {
           addToTMXList(tmxData.data);
           onload();
           return;
         }

         var xmlhttp = new XMLHttpRequest(); // check the data format ('tmx', 'json')

         var format = me.utils.file.getExtension(tmxData.src);

         if (xmlhttp.overrideMimeType) {
           if (format === "json") {
             xmlhttp.overrideMimeType("application/json");
           } else {
             xmlhttp.overrideMimeType("text/xml");
           }
         }

         xmlhttp.open("GET", tmxData.src + api.nocache, true);
         xmlhttp.withCredentials = me.loader.withCredentials; // set the callbacks

         xmlhttp.ontimeout = onerror;

         xmlhttp.onreadystatechange = function () {
           if (xmlhttp.readyState === 4) {
             // status = 0 when file protocol is used, or cross-domain origin,
             // (With Chrome use "--allow-file-access-from-files --disable-web-security")
             if (xmlhttp.status === 200 || xmlhttp.status === 0 && xmlhttp.responseText) {
               var result = null; // parse response

               switch (format) {
                 case "xml":
                 case "tmx":
                 case "tsx":
                   // ie9 does not fully implement the responseXML
                   if (me.device.ua.match(/msie/i) || !xmlhttp.responseXML) {
                     if (window.DOMParser) {
                       // manually create the XML DOM
                       result = new DOMParser().parseFromString(xmlhttp.responseText, "text/xml");
                     } else {
                       throw new Error("XML file format loading not supported, use the JSON file format instead");
                     }
                   } else {
                     result = xmlhttp.responseXML;
                   } // converts to a JS object


                   var data = me.TMXUtils.parse(result);

                   switch (format) {
                     case "tmx":
                       result = data.map;
                       break;

                     case "tsx":
                       result = data.tilesets[0];
                       break;
                   }

                   break;

                 case "json":
                   result = JSON.parse(xmlhttp.responseText);
                   break;

                 default:
                   throw new Error("TMX file format " + format + "not supported !");
               } //set the TMX content


               addToTMXList(result); // fire the callback

               onload();
             } else {
               onerror(tmxData.name);
             }
           }
         }; // send the request


         xmlhttp.send();
       }
function preloadTMX ( tmxData , onload , onerror ) { function addToTMXList ( data ) { // set the TMX content tmxList [ tmxData . name ] = data ; // add the tmx to the levelDirector if ( tmxData . type === "tmx" ) { me . levelDirector . addTMXLevel ( tmxData . name ) ; } } //if the data is in the tmxData object, don't get it via a XMLHTTPRequest if ( tmxData . data ) { addToTMXList ( tmxData . data ) ; onload ( ) ; return ; } var xmlhttp = new XMLHttpRequest ( ) ; // check the data format ('tmx', 'json') var format = me . utils . file . getExtension ( tmxData . src ) ; if ( xmlhttp . overrideMimeType ) { if ( format === "json" ) { xmlhttp . overrideMimeType ( "application/json" ) ; } else { xmlhttp . overrideMimeType ( "text/xml" ) ; } } xmlhttp . open ( "GET" , tmxData . src + api . nocache , true ) ; xmlhttp . withCredentials = me . loader . withCredentials ; // set the callbacks xmlhttp . ontimeout = onerror ; xmlhttp . onreadystatechange = function ( ) { if ( xmlhttp . readyState === 4 ) { // status = 0 when file protocol is used, or cross-domain origin, // (With Chrome use "--allow-file-access-from-files --disable-web-security") if ( xmlhttp . status === 200 || xmlhttp . status === 0 && xmlhttp . responseText ) { var result = null ; // parse response switch ( format ) { case "xml" : case "tmx" : case "tsx" : // ie9 does not fully implement the responseXML if ( me . device . ua . match ( / msie / i ) || ! xmlhttp . responseXML ) { if ( window . DOMParser ) { // manually create the XML DOM result = new DOMParser ( ) . parseFromString ( xmlhttp . responseText , "text/xml" ) ; } else { throw new Error ( "XML file format loading not supported, use the JSON file format instead" ) ; } } else { result = xmlhttp . responseXML ; } // converts to a JS object var data = me . TMXUtils . parse ( result ) ; switch ( format ) { case "tmx" : result = data . map ; break ; case "tsx" : result = data . tilesets [ 0 ] ; break ; } break ; case "json" : result = JSON . parse ( xmlhttp . responseText ) ; break ; default : throw new Error ( "TMX file format " + format + "not supported !" ) ; } //set the TMX content addToTMXList ( result ) ; // fire the callback onload ( ) ; } else { onerror ( tmxData . name ) ; } } } ; // send the request xmlhttp . send ( ) ; }
preload TMX files
@ignore
preload TMX files