understanding LoadVars()

  • Willy
  • Graduate
  • Graduate
  • Willy
  • Posts: 199

Post 3+ Months Ago

I have a php script that posts &n=4& ....

var c = new LoadVars();
c.load("http://www.cashportals.net/justin/dbreturn.php","_self","POST");

AFTER running this if i do c["n"] i am given a null, in fact i cannot reference the posted vars once its done

hoever

if i add a :
c.onLoad=function(){
this.n; //exists HERE!
}

so i can really only grab my posted variables from within the onload function? The more i am playing with this the more confused i'm getting.

So if i want to use have a gloabal scoped variable i need to duplicate it into its own container in the onLoad functioN????? This is getting worse by the second


pseudo code from recent debotchery:
content is a textbox........


Code: [ Select ]
var c = new LoadVars();
c.load("http://www.cashportals.net/justin/dbreturn.php","_self","POST");
c.onLoad = function(){

content.text=this.n;
}

content.text += "recent"+c.blahh+"bye"+i+currentPic+"icount="+i+"width = "+this["pic"+i]._width;
  1. var c = new LoadVars();
  2. c.load("http://www.cashportals.net/justin/dbreturn.php","_self","POST");
  3. c.onLoad = function(){
  4. content.text=this.n;
  5. }
  6. content.text += "recent"+c.blahh+"bye"+i+currentPic+"icount="+i+"width = "+this["pic"+i]._width;


-------
OUTPUT:
--------
this flashes breifly "recentbye4 ..."
but then when the script ends it reads "7"

this is mind boggeling to me

My base assumption woudl be that c.loadvars puts eveyritng into c ... I would think c.<var> would get me what i'm looking at anywhere in my code after I post that. I guess this assumption is wroing?

thanks

willy
  • 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

LoadVars() does not load the data instantaneously, so the data being loaded in can only be accessed once ALL of the data is FULLY loaded in. This is the point of the onLoad dynamic event handler. It allows you to check when all the data is loaded and then do what you need to do once the data is loaded. After it is fully loaded, the data can be accessed any time you want by targeting the LoadVars object.

For example, in your example your LoadVars() object is called "c". So if you want to target a variable loaded into that LoadVars() object you would use c.variableName. So your assumption is right, the only thing you is you have to be sure that the data is loaded in before you can target it like that.
  • Willy
  • Graduate
  • Graduate
  • Willy
  • Posts: 199

Post 3+ Months Ago

Code: [ Select ]
var c = new LoadVars();
c.load("http://www.cashportals.net/justin/dbreturn.php","_self","POST");
c.onLoad = showLoad;
statusBox.content.text="HELLO "+c.n+"OutLast.";

//FUNCTIONS /////
function showLoad(){
    for(j=1;j<this.n;j++){
    //dosent do crap.
    }
    //statusBox.content.text="in onload"+c.n+"<-output?";
    
}
  1. var c = new LoadVars();
  2. c.load("http://www.cashportals.net/justin/dbreturn.php","_self","POST");
  3. c.onLoad = showLoad;
  4. statusBox.content.text="HELLO "+c.n+"OutLast.";
  5. //FUNCTIONS /////
  6. function showLoad(){
  7.     for(j=1;j<this.n;j++){
  8.     //dosent do crap.
  9.     }
  10.     //statusBox.content.text="in onload"+c.n+"<-output?";
  11.     
  12. }


I run this twice....

time 1: statusBox.content commented out
Expecting to se "Hello 7 OutLast"
Result: "Hello Outlast"

time 2: add in statusBox assignment
Result : "in onload 7 <--output?"

When this executes it DOES recognize my loaded variable. But shouldnt the text have been overridden with the OutLast assignment???? Is loadVars a thread or something similar??

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

Post 3+ Months Ago

Before your data is actually loaded in, all the actions in the frame are read and initialized. So despite the onLoad occurring before the statusBox.content line, the statusBox.content line will still be run before the external data is loaded in.

And your result returning just "Hello Outlast" is because c.n is undefined and has no value yet.
  • Willy
  • Graduate
  • Graduate
  • Willy
  • Posts: 199

Post 3+ Months Ago

Thats sorta what i was guessing was going on

Unfortunately, this kinda puts me back at square 1. Tutorials i've been reading just use posted variables at their leisure. I don't see a method for stalling while the loading takes place:
http://actionscript-toolbox.com/samplemx_php.php

i've even gone as far as trying something like
while( c["id"+(c.n-1)] =="" ){
}

in an effort to make sure everyting is loaded in.

To no avail, i'm about to punch a very large dent into my wall....
  • norie
  • Novice
  • Novice
  • norie
  • Posts: 18
  • Loc: bako

Post 3+ Months Ago

Code: [ Select ]
var c = new LoadVars();
c.onLoad = function(success){ content.text = (success) ? this.n : "Load Failed";}
c.load("http://www.cashportals.net/justin/dbreturn.php","_self","POST");
content.text += "recent"+c.blahh+"bye"+i+currentPic+"icount="+i+"width = "+this["pic"+i]._width;
  1. var c = new LoadVars();
  2. c.onLoad = function(success){ content.text = (success) ? this.n : "Load Failed";}
  3. c.load("http://www.cashportals.net/justin/dbreturn.php","_self","POST");
  4. content.text += "recent"+c.blahh+"bye"+i+currentPic+"icount="+i+"width = "+this["pic"+i]._width;


you might also want to use a relative path instead of absolute. (dbreturn.php)
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Willy wrote:
Thats sorta what i was guessing was going on

Unfortunately, this kinda puts me back at square 1. Tutorials i've been reading just use posted variables at their leisure. I don't see a method for stalling while the loading takes place:
http://actionscript-toolbox.com/samplemx_php.php

i've even gone as far as trying something like
while( c["id"+(c.n-1)] =="" ){
}

in an effort to make sure everyting is loaded in.

To no avail, i'm about to punch a very large dent into my wall....
Well the whole while() loop thing is exactly what the onLoad event handler is for... the code doesn't get executed until the data is loaded and can be read/manipulated in Flash. So basicall your "stall" would be any actions outside of the onLoad event function and then in the onLoad goes the actions you want to occur after the "stall".

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 14 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.