Forum de discussion
Forum « Flash et Shockwave » (archives)
Re: double chargement d'XML [Pb temps de chargement]
Envoyé: 4 décembre 2005, 13h08 par popo
merci bcp pour ton conseil, j'ai remanié un peu le code, mais hélas ca merdouille toujours...
le code ressemble maintenant à ceci ;
fscommand("allowscale", 0);
function setGlobalStyleFormat(){
globalStyleFormat.face = 0xEFEFEF;
// globalStyleFormat.background = 0xCCCCCC;
globalStyleFormat.arrow = 0xAAAAAA;
globalStyleFormat.darkshadow = 0xAAAAAA;
globalStyleFormat.shadow = 0xEFEFEF;
globalStyleFormat.highlight = 0xEFEFEF;
globalStyleFormat.highlight3D = 0xAAAAAA;
globalStyleFormat.scrollTrack = 0xFFFFFF;
globalStyleFormat.selection = 0xAFAFAF;
globalStyleFormat.textSelected = 0x000000;
globalStyleFormat.textColor = 0x666666;
globalStyleFormat.textFont = "_sans";
globalStyleFormat.textSize = 13;
globalStyleFormat.applyChanges();
}
setGlobalStyleFormat();
// --::[ combo/listboxes example ]::-- //
// --::[ 1. set up xml file like this ]::-- //
/*
<menuitems>
<item title='your title'>
<images directory="images">
<imageNode jpegURL="pic1.jpg" thumbURL="tn1.jpg" title="tn title">Comments on Image 0</imageNode>
</images>
</item>
</menuitems>
*/
var str = _url;
endswf = str.lastIndexOf(".swf");
pos1 = str.lastIndexOf("/");
pos2 = str.lastIndexOf("\\");
nom_copine = str.substring(math.max(pos1,pos2)+1,endswf);
trace("1 getting name of the swf file:" + nom_copine);
fichier_xml = new XML();
fichier_xml._tl = this;
fichier_xml.ignoreWhite = true;
fichier_xml.onLoad = loader;
fichier_xml.load('cops.xml');
//the cops.xml contains information the XML file to load
//with the name of the swf file, we can get Field_XML
function loader(success){
if (success)
{if (this.loaded && this.hasChildNodes)
{
if (this.firstChild.nodeName.toLowerCase() == "content")
{ var nm = this.firstChild.childNodes;
var j = 0;
var ii = -1;
var max_ligne = 5;
for ( var i = 0; i<=nm.length; i++)
{//trace (">"+nm[i].attributes.name+"<");
if (nm[i].nodeName == "serie" && nm[i].attributes.name == nom_copine)
{ //trace("trouve");
Field_commentaire = nm[i].attributes.commentaire;
Field_xml = nm[i].attributes.xml;
}
}
}
}}
trace("2 obtention of the file containing the picture to display:" + Field_xml);
trace(" comment:" + Field_commentaire);
//filling of the name field
nomcopine = nom_copine;
//myGallery.imageText = Field_commentaire;
trace ("3 loading of the XML file found:"+Field_xml);
// --::[ 3. load and parse XML ]::-- //
menu_items_xml = new XML();
menu_items_xml._tl = this;
menu_items_xml.ignoreWhite = true;
menu_items_xml.load(Field_xml);
}
//parse code from xml file
menu_items_xml.onLoad = function (success){
if(!success)
break;
trace ("4 File loaded:"+Field_xml);
var root = this.firstChild;
var n = root.childNodes.length;
var m = this._tl.menu_cb;
for (var i = 0; i < n; i++){
m.addItem(root.childNodes[i].attributes.title,root.childNodes[i].firstChild);
}
m.setChangeHandler('cb_handler', this._tl)
// --::[ 4. attach the gallery ]::-- //
g1 = this._tl.attachMovie("FGallerySymbol","myGallery",10,{_x:0, _y:0});
g1.setTnStageSide('left');
g1.setColumns(3);
g1.setTnSize(84, 84);
g1.setSize(800,600);
g1.setTnTitleStyle('title'); // can be 'name' or 'title'
//select first item from combo/listbox
m.setSelectedIndex(0);
}
// --::[ 5. set up changehandler for combo/listbox ]::-- //
function cb_handler(cb){
//get data from selected item
var tdata = cb.getSelectedItem().data;
//make xml node for gallery - IMPORTANT
var menu_data_xml = new XML([tdata]);
//set xml node
g1.setXMLFile(menu_data_xml);
}
stop();
Il me semble que cela correspond bien à ce que tu proposais. Toutefois, je me pose une ptite question ; est ce que le premier chargement ne gène pas le second ?
-code du premier chargement
fichier_xml = new XML();
fichier_xml._tl = this; -> ca sert à koi ca ?
fichier_xml.ignoreWhite = true;
fichier_xml.onLoad = loader;
fichier_xml.load('cops.xml');
-code du 2eme chargement
menu_items_xml = new XML();
menu_items_xml._tl = this;
menu_items_xml.ignoreWhite = true;
menu_items_xml.load(Field_xml);
Cordialement
Réponses
|