PDA

View Full Version : Global Vars



lbeetles
November 13th, 2003, 12:33 PM
Hi All,

I have this code in a movie, the movie loads fine on it's own but when i load it into another movie it does not work.

I think this is to do with global vars, but im not sure.

Could someone please have a look at the code to see if it is the case. If it is could someone please show me how and where i would change the vars so they are global vars.

Here is the script.

//--------------------------------------------------------------------------------
//XML ONLOAD EVENT - INVOKED WHEN XML IS LOADED
//--------------------------------------------------------------------------------
function onImgLoaded(success) {
if (success) {
mainTag = new XML();
mainTag.ignoreWhite = true;
for (var i = 0; i<this.childNodes.length; i++) {
if (this.childNodes[i].nodeValue == null && this.childNodes[i].nodeName.toLowerCase() == "comboitems") {
mainTag = this.childNodes[i];
}
}
delete imgXML;
arrImgXML02 = [];
var item = 0;
for (var i = 0; i<mainTag.childNodes.length; i++) {
if (mainTag.childNodes[i].nodeName != null) {
arrImgXML02[item] = {};
for (var j = 0; j<mainTag.childNodes[i].childNodes.length; j++) {
var itemName = mainTag.childNodes[i].childNodes[j];
if (itemName.nodeName == "code") {
arrImgXML02[item].code = itemName.firstChild.nodeValue;
}
if (itemName.nodeName == "description") {
arrImgXML02[item].label = itemName.firstChild.nodeValue;
}
if (itemName.nodeName == "groupimage") {
arrImgXML02[item].groupImg = itemName.firstChild.nodeValue;
}
}
item++;
}
}
delete mainTag;
imgXML_lb.setDataProvider(arrImgXML02);
} else {
trace("no XML loaded");
}
}
//--------------------------------------------------------------------------------
// ONLOAD EVENT CALLBACK INVOKED WHEN TEXT IS LOADED
//--------------------------------------------------------------------------------
function onTextLoaded(success) {
if (success) {
_root.text_field.htmlText = this.imgText;
} else {
_root.text_field.text = "sorry, there seems to be a problem and text could not be loaded";
}
}
//--------------------------------------------------------------------------------
// CHANGEHANDLER FOR LISTBOX - LOADS IMAGE INTO SCROLLPANE
//--------------------------------------------------------------------------------
function handleImg(_lb) {
var img = _lb.getSelectedItem().groupImg;
xmlImg_sp.loadScrollContent(img);
}
//--------------------------------------------------------------------------------
// INITIALIZE MOVIE... LOAD TEXT, XML,
//--------------------------------------------------------------------------------
if (!inited) {
inited = true;
text_field.background = true;
text_field.backgroundColor = 0x909090;
text_field.border = true;
text_field.borderColor = 0x666666;
//
imgXML_lb.setAutoHideScrollBar(true);
//
var imgXML = new XML();
imgXML.ignoreWhite = true;
imgXML.onLoad = onImgLoaded;
imgXML.load("image.xml");
}
stop();

lbeetles
November 16th, 2003, 05:11 PM
Anyone any idea???

jsk
November 17th, 2003, 06:37 AM
Are you loading your movie into a _level (i.e. using loadMovieNum()) if so then using _root (which you're using in onTextLoaded()) will reference the main timeline of the level from which it is called e.g. _level3 if you've loaded into level3.

If this is what's happening try using _level0 instead of _root

lbeetles
November 17th, 2003, 06:56 AM
Im loading each movie into a movie clip. I've used the transition tutorial on kirupa.

jsk
November 17th, 2003, 09:59 AM
I'm not sure which tute you mean.

When you say it's not working, what do you mean - it's not loading xml, it's not parsing xml, or it's not setting the text field correctly?

Where are you loading the XML relative to the position of the handling functions? I'd have a look at the scope of "this" inthis.childNodes[i].nodeValue etc in onImgLoaded() bearing. If it's moved as a result of loading into a MC instance you might consider passing it as a param to onImgLoaded()?