loadVars how do I access the variables loaded?

  • yoogie8
  • Newbie
  • Newbie
  • yoogie8
  • Posts: 8
  • Loc: London

Post 3+ Months Ago

Hi there

I'm loading in an external php file, but don't know how to access the variables once they are loaded.

In the following example the first trace within the showValues function works fine. The second trace returns 'Undefined'

How do I access the variables loaded into the newsList object?

Ben

newsList = new LoadVars();
newsList.load('myphp.php');
newsList.onLoad = showValues;

function showValues(){
trace(this.date1); //this one works fine
}

trace(newsList.date1); //this one returns 'Undefined'
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

It returns undefined because it is located outside of the onLoad handler. The data has to be fully loaded before you can access any of the variables.
  • yoogie8
  • Newbie
  • Newbie
  • yoogie8
  • Posts: 8
  • Loc: London

Post 3+ Months Ago

how do I do that?
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

You already do
Code: [ Select ]
newsList.onLoad = showValues;

function showValues(){
trace(this.date1); //this one works fine
}
  1. newsList.onLoad = showValues;
  2. function showValues(){
  3. trace(this.date1); //this one works fine
  4. }


You call the showValues function onLoad, thats why that function returns the proper value.
  • yoogie8
  • Newbie
  • Newbie
  • yoogie8
  • Posts: 8
  • Loc: London

Post 3+ Months Ago

to be able to access the same variable outside of the onLoad function, do I need to create new global variables?:

var datesVar = newArray();
var titlesVar = newArray();

newsList = new LoadVars();
newsList.load('http://chjm.code-uk.com/news/flash.php?action=list');
newsList.onLoad = showValues;

function showValues() {
for (i=0, i<=10, i++) {
this.dates[i] = datesVar[i];
this.titles[i] = titlesVar [i];
}
}
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Any actions that require that information should be done in the onLoad. There really shouldn't be any need to do it outside of the onLoad handler.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 24 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.