PDA

View Full Version : Can't I use onLoad for 2 things?



ben_is_sparky
August 12th, 2005, 09:06 AM
I'm making a little portfolio site, mostly to get to grips with xml and LoadVars a bit better. But I@m having this problem - I load the first xml file (news.xml) while the preloader goes, but only use the onLoad function to check it when I need to use it. I decided this would be good because it doesn't clutter up my preloader and also, I needed to have the onLoad when I wanted to get the data out it seemed. I got the news working, but then I tried to load some more variables from a text file (text_vars.txt) by the same process. When I come to load them (also using onLoad, to check that they are actually loaded before I try to access them)* it clears the news page. I don't know why this is, or ho to stop it, but It only happened after I added in the second onLoad so I think it's something to do with that. I tried taking out the second onLoad and just calling the data from the text file, with just the time between it being told to load and you navigating to that page ensuring that it is loaded in time. Can someone have a look at my .fla and see what I'm doing wrong? It's just annoying me.

I will be wanting to load another xml file too, which holds all the information about the pictures.

Edit: Files are too big to attach - here they are:
http://benspencer.freefronthost.com/xml_problems_files.zip

bandinopla
August 12th, 2005, 09:26 AM
I can't download the file... is corrupted, or that what I see... anyway... mabie your problem is that you are using the same object to load everything...

if you whant, put the code that load the files...

ben_is_sparky
August 12th, 2005, 12:42 PM
Try downloading with THIS LINK (http://benspencer.freefronthost.com/xml_problems_files.zip) instead maybe?

The code I'm using is this:

On the first frame, which is my preloader I have this:

newsXML = new XML();
newsXML.ignoreWhite = true;
newsXML.load("news.xml")

loadedTextVars = new loadVars();
loadedTextVars.load("text_vars.txt");

And then on the News Page (In a nested MC, on frame 3):

_root.newsXML.onLoad = function(success){
if (success){
//I've got the stuff for putting the info into the dynamic textbox here
}
}

And in another nested MC, on the 'About Me' page is this code:

_root.loadedTextVars.onLoad = function(success){
if(success){
about_text.text = _root.loadedTextVars.about_intro;
}
}

I want a similar deal to the news page to go on the Thumbnails page, and the same as the About page to happen on both the pictures and the contact pages aswell, so having it only work once is a real problem :p

I'm sure it's somethign silly and small that I've missed, I'm fairly new to working with external files. ;)

bandinopla
August 12th, 2005, 12:51 PM
no, i still can't download the file. But...

when you make a OBJECT.load(...) U are loading data into that object... there is no need to put in the frame 3, like U said, in the new section the onLoad event...

If you better download the data in the preload frame of all the movie... you could later, in frame 3 chose retrive the data of your loadedTextVars... doing... textbox.text=loadedTextVars.theVar

...

ben_is_sparky
August 13th, 2005, 02:47 PM
But if I don't use onLoad, is there a way I can be sure that it hasd loaded before I try to access it?

icio
August 13th, 2005, 04:29 PM
you need to set `onLoad` before you call `load` incase the text xml loads before you get to frame 3.

or if you want to check it at certain intervals:
if (newsXML.getBytesLoaded() == newsXML.getBytesTotal()) { /*etc... */ }

hope this helps :thumb:
this is an AS question, right ? there is a whole section dedicated to Flash :)

ben_is_sparky
August 14th, 2005, 04:19 AM
Oh, cool, thanks - I'll try doing that instead. :)

Yeah, it probably should be in the AS or FMX section, but It's to do with xml, so it kinda fits here too :p

icio
August 14th, 2005, 08:34 AM
XML isn't server side either ;), infact - XML can't be classed as server or client-side, it's simply a text file.