The code below reads from an xml file, builds an array and then fades the text from the array elements in and out. However, the onenterframe function begins to play before the array has finished loading, so the first message or two does not appear. How does one code this so that the function that displays the messages does not run until the file load is done? - G
var interval:Number = new Number (55);
// counter for transitions
var i:Number = new Number (0);
// current object in array
var j:Number = new Number (0);
// in or out
var inOutNothing:String = new String(‘in’);
this.createTextField(‘textFaderText’, this.getNextHighestDepth(), 0,0,300, 30);
this.createEmptyMovieClip(‘textFader’, this.getNextHighestDepth());
textFader.beginFill(0xFFFFFF);
textFader.moveTo(0, 0);
textFader.lineTo(300, 0);
textFader.lineTo(300, 30);
textFader.lineTo(0, 30);
textFader.lineTo(0, 0);
textFader.endFill();
myxml = new XML();
myxml.ignoreWhite = true;
myxml.onLoad = loadxml;
myxml.load(“msg.xml”);
function loadxml(loaded) {
if (loaded) {
myxml = this.firstChild;
images = [];
textArray = [];
total = myxml.childNodes.length;
for (i=0; i<total; i++) {
textArray* = myxml.childNodes*.attributes.imgtitle;
trace(textArray*);
}
} else {
image_dis = “Xml not loaded”;
}
}
this.onEnterFrame = function ():Void {
// if fading in
if (inOutNothing == ‘in’) {
// if it the first time on this item
if (i <= 1) {
formatA.color = 0xFF0000; // red
formatA.italic = true;
formatA.font = “Arial”;
formatA.size = 12;
textFaderText.text = textArray[j];
//textFaderText.setTextFormat (formatA);
textFaderText.setTextFormat(new TextFormat("Arial", 12));
//var scottfieldTextFormat = textFaderText.getTextFormat();
//trace(scottfieldTextFormat.font);
}
textFader._alpha = 100 - (100/interval) * i;
if (i == interval) {
i=0;
inOutNothing = 'nothing';
}
} else if (inOutNothing == 'out') {
textFader._alpha = (100/interval) * i;
if (i == interval) {
//if (j == (textArray.length-1)) { delete this.onEnterFrame; }
if (j == (textArray.length-1)) { j=-1; }
i=0;
inOutNothing = 'in';
j++;
}
} else {
if (i == interval) { i=0; inOutNothing = 'out'; }
}
i++;
}