Hi all,
I have a file where I load some XML, set up a bunch of the data into arrays, then pull it out to set up things like URLs, Image paths (for a bunch of UILoader components) all to make a banner rotator for my site.
I know it works - but lets say i put all the XML loading code on frame one, along with a preloader and on load complete function triggers, then in a new scene on frame one, have all my UILoader components, text fields, etc being populated - when I upload, it would load everything successfully maybe 1 in every 8 refreshes.
So, knowing flash, i pushed my timelines out from one frame to around 5, placing all of the text fields, image loaders, etc in frame one, but only calling the code on frame 5 to set everything up. For some reason this worked better, actually loading the external files around 99% of the time, and loading the XML 100% of the time.
My issue now is, say i load the file, click a link and go to a page - if i click the back button, maybe 90% of the time the file will load with a bunch of undefined text fields - my UILoaders are all empty, but i know the XML is still loading, as when i roll over each button… suddenly images will start to pop on. I swear - 13 years developing in Flash and i still don’t feel like I can figure out simple loading of files… there’s always something.
We did just make the transition to CS5, but this type of issue is nothing new to me. See below for my code (it may be hacky in some parts, but no errors):
stop();
//we can reference just the 'com' folder as we've designated the
//class path setting under publish-->settings
import com.greensock.TweenLite;
import com.greensock.easing.*;
var randNum:Number = Math.ceil(Math.random()*2);
trace (randNum);
// the end of your XML call action
// "filename.xml?" + randNum
//==================================================================
//REMOTE load in the key xml LIVE VERSION
var keyReq:URLRequest=new URLRequest("/cont/keys/keys.xml");
//var keyReq:URLRequest=new URLRequest("/cont/keys/keys.xml"+"?"+randNum);
var XMLkeyloader:URLLoader = new URLLoader();
//declare main XML value (slides)
var content_loc:XML;
//array to store the total length of the XML (total # of surgeries)
var lengthArray:Array = new Array();
//page titles - this is to call the name into the "activity name" Sponsored By title text
var nameArray:Array = new Array();
//this array stored links to actual surgery pages
var linkArray:Array = new Array();
//calls the IDs into an array
var idArray:Array = new Array();
function keyLoader(e:Event):void{
content_loc = new XML(XMLkeyloader.data);
//get total number of surgeries
lengthArray.push(content_loc.surgery.length());
//match the flash var on the word press page to the specific key_id
//This is all to set up the actual current activity
for (var i:int=0; i<lengthArray[0]; i++) {
//name is just the text name of the surgery, i.e. 'Virtual Nose Job'
nameArray.push(content_loc.surgery*.@sname);
//this array stores links to actual surgery pages
linkArray.push(content_loc.surgery*.@link);
//id is the id/folder names of the activities
idArray.push(content_loc.surgery*.@key_id);
//NOTE - to call these variables from the above arrays refer to them
//as such: (urlArray[0] + "xml/content.xml")
}
}
//create an array of our button instance names
var bNameArray:Array = new Array();
for (var e:int=0; e<5; e++){
bNameArray.push("b"+(e+1));
trace(bNameArray[e]);
}
//LOAD THE INTERFACE HERE-------------------------------------------------------------
addEventListener(Event.ENTER_FRAME, interfacePreloader);
function interfacePreloader(event:Event) :void {
var bytestotal = stage.loaderInfo.bytesTotal;
var bytesloaded = stage.loaderInfo.bytesLoaded;
var pctLoaded:int = bytesloaded * 100 / bytestotal;
loading_mc.loading_dtext.text = String(pctLoaded) + "%";
if (bytesloaded >= bytestotal) {
removeEventListener(Event.ENTER_FRAME, interfacePreloader);
//fadeOutPreloader();
play();
}
}
//XML Listeners
//Load XML
XMLkeyloader.addEventListener(Event.COMPLETE, keyLoader);
XMLkeyloader.load(keyReq);
then in scene 2, which populates the actual UIloaders:
stop();
//says which button we're currently on
var btnVar:String;
//set up var
var imageSource:String;
//set up var
var textSource:String;
//initialize wrapper to load most recent activity
btnVar = "b5";
mainLoader.source = "/images/activity_loaders/" + idArray[lengthArray[0] - 1] + ".jpg";
titleTxt.surgeTitle.text = String("New! "+nameArray[lengthArray[0] - 1]);
TweenLite.to(pointer, .4, {y:Math.round(b5.y)});
b1.btnLoader.source = "/images/activity_thumbs/" + idArray[lengthArray[0] - 5] + ".jpg";
b2.btnLoader.source = "/images/activity_thumbs/" + idArray[lengthArray[0] - 4] + ".jpg";
b3.btnLoader.source = "/images/activity_thumbs/" + idArray[lengthArray[0] - 3] + ".jpg";
b4.btnLoader.source = "/images/activity_thumbs/" + idArray[lengthArray[0] - 2] + ".jpg";
b5.btnLoader.source = "/images/activity_thumbs/" + idArray[lengthArray[0] - 1] + ".jpg";
b1.buttonMode = true;
b2.buttonMode = true;
b3.buttonMode = true;
b4.buttonMode = true;
b5.buttonMode = true;
function doctorCheck(){
//set main image after fade out
fadeL.gotoAndPlay("pl")
}
//set up main button
scrubIn.addEventListener(MouseEvent.CLICK, scrubClick);
//tell each thumb to go to surgery if clicked
b1.addEventListener(MouseEvent.CLICK, scrubClick);
b2.addEventListener(MouseEvent.CLICK, scrubClick);
b3.addEventListener(MouseEvent.CLICK, scrubClick);
b4.addEventListener(MouseEvent.CLICK, scrubClick);
b5.addEventListener(MouseEvent.CLICK, scrubClick);
function scrubClick(event:MouseEvent):void
{
//set main bkg image
if (btnVar == "b5")
{
//get URL of current surgery
//grab the URL out of the url array from sponsors.xml
var request5:URLRequest = new URLRequest(linkArray[lengthArray[0] - 1]);
navigateToURL(request5, "_parent");
}
if (btnVar == "b4")
{
//get URL of current surgery
//grab the URL out of the url array from sponsors.xml
var request4:URLRequest = new URLRequest(linkArray[lengthArray[0] - 2]);
navigateToURL(request4, "_parent");
}
if (btnVar == "b3")
{
//get URL of current surgery
//grab the URL out of the url array from sponsors.xml
var request3:URLRequest = new URLRequest(linkArray[lengthArray[0] - 3]);
navigateToURL(request3, "_parent");
}
if (btnVar == "b2")
{
//get URL of current surgery
//grab the URL out of the url array from sponsors.xml
var request2:URLRequest = new URLRequest(linkArray[lengthArray[0] - 4]);
navigateToURL(request2, "_parent");
}
if (btnVar == "b1")
{
//get URL of current surgery
//grab the URL out of the url array from sponsors.xml
var request1:URLRequest = new URLRequest(linkArray[lengthArray[0] - 5]);
navigateToURL(request1, "_parent");
}
}
//BUTTON 1 PROGRAMMING
//program the buttons to load the appropriate links for each new surgery
b1.addEventListener(MouseEvent.ROLL_OVER, b1Click);
function b1Click(event:MouseEvent):void
{
TweenLite.to(pointer, .4, {y:Math.round(b1.y)});
//set main scrub in to b1 URL
btnVar = "b1";
//set main bkg image
//mainLoader.source = "/images/activity_loaders/" + idArray[lengthArray[0] - 5] + ".jpg";
imageSource = "/images/activity_loaders/" + idArray[lengthArray[0] - 5] + ".jpg";
//titleTxt.surgeTitle.text = String("Scrub in with: "+nameArray[lengthArray[0] - 5]+ "!");
textSource = "Scrub in with: "+nameArray[lengthArray[0] - 5]+ "!";
//check if Dr suzi or Jeff (set up in XML)
doctorCheck();
}
//BUTTON 2 PROGRAMMING
//program the buttons to load the appropriate links for each new surgery
b2.addEventListener(MouseEvent.ROLL_OVER, b2Click);
function b2Click(event:MouseEvent):void
{
TweenLite.to(pointer, .4, {y:Math.round(b2.y)});
//set main scrub in to b2 URL
btnVar = "b2";
//set main bkg image
imageSource = "/images/activity_loaders/" + idArray[lengthArray[0] - 4] + ".jpg";
textSource = "Try out: "+nameArray[lengthArray[0] - 4]+ "!";
//check if Dr suzi or Jeff (set up in XML)
doctorCheck();
}
//BUTTON 3 PROGRAMMING
//program the buttons to load the appropriate links for each new surgery
b3.addEventListener(MouseEvent.ROLL_OVER, b3Click);
function b3Click(event:MouseEvent):void
{
TweenLite.to(pointer, .4, {y:Math.round(b3.y)});
//set main scrub in to b3 URL
btnVar = "b3";
//set main bkg image
imageSource = "/images/activity_loaders/" + idArray[lengthArray[0] - 3] + ".jpg";
textSource = "Sharpen your surgical skills with: "+nameArray[lengthArray[0] - 3]+ "!";
//check if Dr suzi or Jeff (set up in XML)
doctorCheck();
}
//BUTTON 4 PROGRAMMING
//program the buttons to load the appropriate links for each new surgery
b4.addEventListener(MouseEvent.ROLL_OVER, b4Click);
function b4Click(event:MouseEvent):void
{
TweenLite.to(pointer, .4, {y:Math.round(b4.y)});
//set main scrub in to b4 URL
btnVar = "b4";
//set main bkg image
imageSource = "/images/activity_loaders/" + idArray[lengthArray[0] - 2] + ".jpg";
textSource = "Have you tried: "+nameArray[lengthArray[0] - 2] + "?";
//check if Dr suzi or Jeff (set up in XML)
doctorCheck();
}
//BUTTON 5 PROGRAMMING
//program the buttons to load the appropriate links for each new surgery
b5.addEventListener(MouseEvent.ROLL_OVER, b5Click);
function b5Click(event:MouseEvent):void
{
TweenLite.to(pointer, .4, {y:Math.round(b5.y)});
//set main scrub in to b5 URL
btnVar = "b5";
//set main bkg image
imageSource = "/images/activity_loaders/" + idArray[lengthArray[0] - 1] + ".jpg";
textSource = "New! "+nameArray[lengthArray[0] - 1];
//check if Dr suzi or Jeff (set up in XML)
doctorCheck();
}
fader.gotoAndPlay(2);
any help is appreciated!!!