ciao.
Ho creato il parsing per un xml come riporto qua sotto:
il problema è che questo parsing viene effettuato in maniera asincrona, mentre vorrei che fosse eseguito in maniera sincrona.codice:function ReadXmlFile() { var m_Pos = [];//posizione bounding volume var m_scene = []; var m_lightmanager = LightsManager; } ReadXmlFile.prototype = { load: function (render) { $.xml("test.xml",{}, function (xml) { $('BVV', xml).each(function readBVV(j) { var str = $(this).text().split(" "); m_Pos[0] = str[0]; m_Pos[1] = str[1]; m_Pos[2] = str[2]; alert(m_Pos); }); $('Textures', xml).each(function readTextures(j) { if ($(this).text().length > 0) { var strTextures = $(this).text().split(";"); for (var k = 0; k < strTextures.length; k++) { render.GetTextureManager().initTexture("TexturesModel/" + strTextures[k]); alert("TexturesModel/" + strTextures[k]); } } }); $('LightsPositions', xml).each(function readLights(i) { $('light', xml).each(function readLight(j) { var str = $(this).text().split(" "); var L1 = new Light(); var col = new Array(4); col[0] = 255; col[1] = 255; col[2] = 255; col[3] = 255; L1.SetColor(col); var dir = new Array(3); dir[0] = str[0]; dir[1] = str[1]; dir[2] = str[2]; L1.SetDirection(dir); render.GetLightManager().add(L1); }); }); $('Batch', xml).each(function readBatches(i) { var m_Mesh = new Mesh(); var vbuffer = new VertexBuffer(); var haveUVFront = false; this.vbuffer = new VertexBuffer(); this.m_Mesh = new Mesh(); var buffer = VertexBuffer(); var Material; $('MaterialType', $(this)).each(function readMaterialType(i) { Material = $(this).text(); }); var ColorFront = new Array(4); var ColorBack = new Array(4); //estraggo il colore front $('ColorFront', $(this)).each(function readColorFront(i) { var str = $(this).text().split(" "); ColorFront[0] = parseFloat(str[0]) / 255; ColorFront[1] = parseFloat(str[1]) / 255; ColorFront[2] = parseFloat(str[2]) / 255; ColorFront[3] = parseFloat(str[3]) / 255; }); //estraggo il coloreback $('ColorBack', $(this)).each(function readColorBack(i) { var str = $(this).text().split(" "); ColorBack[0] = parseFloat(str[0]) / 255; ColorBack[1] = parseFloat(str[1]) / 255; ColorBack[2] = parseFloat(str[2]) / 255; ColorBack[3] = parseFloat(str[3]) / 255; }); $('Positions', $(this)).each(function readPosition(i) { var str = $(this).text(); this.item = new ItemData(); this.item.AddBulkValue(str, " "); vbuffer.SetItemDataAndCreateBuffer(this.item, "position", 3); }); $('Normals', $(this)).each(function readNormals(i) { var str = $(this).text(); this.item = new ItemData(); this.item.AddBulkValue(str, " "); vbuffer.SetItemDataAndCreateBuffer(this.item, "normal", 3); }); $('UVFront', $(this)).each(function readUVFront(i) { var str = $(this).text(); haveUVFront = true; this.item = new ItemData(); this.item.AddBulkValue(str, " "); vbuffer.SetItemDataAndCreateBuffer(this.item, "texcoord0", 2); }); $('UVBack', $(this)).each(function readUVBack(i) { var str = $(this).text(); haveUVFront = true; this.item = new ItemData(); this.item.AddBulkValue(str, " "); vbuffer.SetItemDataAndCreateBuffer(this.item, "texcoord1", 2); }); var material; material = new TextureEffectDouble(ColorBack, ColorFront, "", "", "Script4LightColorV", "Script4LightColorF", m_gl); alert("__________si"); alert("vertex buffer1"); m_Mesh.AttachMaterial(material); alert("vertex buffer2"); m_Mesh.SetVertexBuffer(vbuffer); alert("vertex buffer3"); m_scene.push(m_Mesh); }); }); },
Io non ci sono riuscito , ho provato a mettere nelle opzioni(almeno penso siano tali ,correggetemi se sbaglio)
$.xml("test.xml",{async:false}, function (xml)
ma non cambia niente.
Ho visto che l'async : false funziona con ajax , è possibile effettuare il parsing con $ajax se in xml l'async non è supportato?
come?
ps.
ho utilizzato jquery perchè volevo essere certo che che funzionasse sotto tutti i browser.
grazie.
grazie.

Rispondi quotando