Flash AS2 LoadVariables doesn't seem to work when swf first loads

I have inherited a flash website where on a page that displays database data uses the LoadVariables method to pull the data and the OnData method to populate fields.  I am using FlashVars in cases where I want to link directly to a specific record.  the AS2 sees the variable and calls the function but for some reason, something between the LoadVariables and OnData methods gets hosed and it doesn't load the from and data.  Now if I navigate the flash a little, then hit the logo which has a gotoAndStop(1) command on it, then it goes to that specific record as it was supposed to but not on the initial load of the flash.  I've attached the code to the function I'm calling since I know at least calling the function works.

function spec_portfolio(mid) {
	gotoAndStop("frame_portfolio");
	this.portfolio_mc["videobutton"]._visible = false;
	this.portfolio_mc["videobutton1"]._visible = false;
	for (var i:Number = 1; i<mediaImages; i++) {
		this.portfolio_mc["ID"+i] = "";
		this.portfolio_mc["MediaPath"+i] = "";
		this.portfolio_mc["mediasquare"+i].loadMovie("blank.jpg", this.portfolio_mc["mediasquare"+i].getNextHighestDepth());
		this.portfolio_mc["mediaframe"+i]._visible = true;
	}
	this.portfolio_mc.loadVariables("stats2.cfm?ID="+mid+"&startrow="+startrow_number2+"", 0, "GET");
	this.portfolio_mc.onData = function() {
	getURL("javascript:alert(\"" + mid + "\");");
		portfolio_mc["edit_btn"].visible = 0;
		var vidstr:String = this.stats_videoflag;
		var vidstr2 = vidstr.substring(0, 1);
		trace(this.stats_videoflag);
		if (vidstr2 != "0") {
			portfolio_mc["videobutton"]._visible = true;
			portfolio_mc["videobutton1"]._visible = true;
		}
		var myod:String = this.Path;
		var myid:String = myod;
		if (myid != undefined) {
			var end:Number = (myid.indexOf("jpg")+3);
			var myid2:String = myid.substr(0, end);
			this.mugshot.loadMovie(myid2, this.mugshot.getNextHighestDepth());
			for (var i:Number = 1; i<mediaImages; i++) {
				var meod:String = eval("portfolio_mc.MediaPath"+i);
				var meid:String = meod;
				if (meid != undefined) {
					var end:Number = (meid.indexOf("jpg")+3);
					var meid2:String = meid.substr(0, end);
					portfolio_mc["mediasquare"+i].loadMovie(meid2);
					//portfolio_mc["mediaframe"+i]._visible = true;
				}
			}
			//this.mugshot._alpha(50);
		}
		var elcounter:Number = ((portfolio_mc.startrow_num*1)+(portfolio_mc.maxrow_num-1));
		if (elcounter>(portfolio_mc.record_num*1)) {
			elcounter = portfolio_mc.record_num;
		}
		portfolio_mc.links_text = portfolio_mc.record_num+" media items found....displaying ";
		portfolio_mc.links_text += portfolio_mc.startrow_num+" thru "+elcounter+"     ";
		var bcounter:Number = ((elcounter)-(portfolio_mc.startrow_num*1)+2);
		trace(bcounter);
		for (var j:Number = bcounter; j<mediaImages; j++) {
			portfolio_mc["mediaframe"+j]._visible = false;
		}
	};
//getURL("javascript:alert(\"" + mid + "\");");
}

Open in new window

ComputerGeek96Asked:
Who is Participating?
 
CyanBlueCommented:
Generally speaking, you have to know some value coming from your server side script...

For example, you are using this PHP script...
<?php
   echo("a=100&b=200&finished=yes");
?>

That will assign those three variables in Flash when the PHP script is fully loaded...  I am sure you understand that far...

So, in Flash, you'd do this...

temp_mc.finished = "no";
temp_mc.loadVariables("test.php, 0, "GET");

temp_mc.onEnterFrame = function ()
{
   if (this.finished == "yes")
   {
      // Your data is loaded...
      // Kill the onEnterFrame loop because you don't need it anymore...
      delete this.onEnterFrame;
      // Do whatever else you need to do with the loaded variables...
      ...
      ...
   }
}

So, the onEnterFrame loop runs until it gets the known variable, finished, from the server and check to see if that flag says 'yes'...

FYI, I am using a temporary movieClip called temp_mc because I don't know if there is a, b and finished variables in the main timeline...  You can create this temp_mc with createEmtpyMovieClip() function call...

I believe that's all there is to it...  I still think you should use LoadVars though...  ;)

CyanBlue
0
 
CyanBlueCommented:
Basically the problem is that it takes time to get the data from the external resource, and you are not waiting long enough to get the data...  You might want to use LoadVars/onData instead of loadVariables functions...  I believe that will solve the problem...

CyanBlue
0
 
ComputerGeek96Author Commented:
i tried to do a loadvars/ondata and it didn't work and it didn't parse the data right though i could have been doing it wrong.  any help on that part would be appreciated....how can i make it wait using the loadvariables.  i inherited this flash site and my client doesn't want to invest much labor cost into it.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
CyanBlueCommented:
I think it is whole lot simpler to use LoadVars rather than adding a wait routine with loadVariables...  Can you post the code you attempted with LoadVars???

CyanBlue
0
 
ComputerGeek96Author Commented:
ok so the LoadVars makes it switch frames right off the bat but the problem now is that the variables aren't populating the dynamic text fields in the porfolio_mc movie clip.  How can I force these variables into that MC.  I've tried changing the 0 to porfolio_mc in the load command and that doesn't do it.  I can manually link the variables by using portfolio_mc.stats_size = mcvars.stats_size but that seems inefficient when the loadvariables did that....i'm closer than i was before....any help with the last part would be great!!
function spec_portfolio() {
	
	var mcvars:LoadVars = new LoadVars();
	
	mcvars.onLoad = function() {
		gotoAndStop("frame_portfolio");
		this.portfolio_mc["videobutton"]._visible = false;
		this.portfolio_mc["videobutton1"]._visible = false;
		for (var i:Number = 1; i<mediaImages; i++) {
			this.portfolio_mc["ID"+i] = "";
			this.portfolio_mc["MediaPath"+i] = "";
			this.portfolio_mc["mediasquare"+i].loadMovie("/blank.jpg", this.portfolio_mc["mediasquare"+i].getNextHighestDepth());
			this.portfolio_mc["mediaframe"+i]._visible = true;
			//this.portfolio_mc["mediaframe"+i]._visible = false;	
		}
		
		portfolio_mc["edit_btn"].visible = 0;
		var vidstr:String = this.stats_videoflag;
		this.portfolio_mc.stats_labels = this.stats_division;
		var vidstr2 = vidstr.substring(0, 1);
		trace(this.stats_videoflag);
		if (vidstr2 != "0") {
			portfolio_mc["videobutton"]._visible = true;
			portfolio_mc["videobutton1"]._visible = true;
		}
		var myod:String = this.Path;
		var myid:String = myod;
		if (myid != undefined) {
			var end:Number = (myid.indexOf("jpg")+3);
			var myid2:String = myid.substr(0, end);
			this.mugshot.loadMovie(myid2, this.mugshot.getNextHighestDepth());
		}
		for (var i:Number = 1; i<mediaImages; i++) {
			var meod:String = eval("portfolio_mc.MediaPath"+i);
			var meid:String = meod;
			if (meid != undefined) {
				var end:Number = (meid.indexOf("jpg")+3);
				var meid2:String = meid.substr(0, end);
				portfolio_mc["mediasquare"+i].loadMovie(meid2);
				//portfolio_mc["videobutton"]._visible = true;
			}
		}
		var elcounter:Number = ((portfolio_mc.startrow_num*1)+(portfolio_mc.maxrow_num-1));
		if (elcounter>(portfolio_mc.record_num*1)) {
			elcounter = portfolio_mc.record_num;
		}
		portfolio_mc.links_text = portfolio_mc.record_num+" media items found....displaying ";
		portfolio_mc.links_text += portfolio_mc.startrow_num+" thru "+elcounter+"     ";
	  var myformat;
	  myformat.bold = false;
	  portfolio_mc.stats_suit.setTextFormat(myformat);
	  if (portfolio_mc.stats_division.indexOf('Centro Men') >= 0 || portfolio_mc.stats_division.indexOf('Centro Guys') >= 0) {
		portfolio_mc.stats_text = 'HEIGHT:\nSUIT:\nWAIST:\nSHIRT:\nINSEAM:\nSHOE:\nHAIR:\nEYES:';
		portfolio_mc.stats_size.visible = false;
		portfolio_mc.stats_hip.visible = false;
		portfolio_mc.stats_chest.visible = false;
	  } else {
		portfolio_mc.stats_text = 'HEIGHT:\nSIZE:\nWAIST:\nHIP:\nINSEAM:\nSHOE:\nHAIR:\nEYES:\nCHEST:';
		portfolio_mc.stats_suit.visible = false;
		portfolio_mc.stats_shirt.visible = false;
	  }
		var bcounter:Number = ((elcounter)-(portfolio_mc.startrow_num*1)+2);
		trace(bcounter);
		for (var j:Number = bcounter; j<mediaImages; j++) {
			portfolio_mc["mediaframe"+j]._visible = false;
		}
	};
	mcvars.load("stats2.cfm?ID="+_root.user_modelid+"&startrow="+startrow_number2+"", 0, "GET");
//getURL("javascript:alert(\"" + mid + "\");");
}

Open in new window

0
 
CyanBlueCommented:
You have to use sendAndLoad() instead of load() function cuz you are sending out variables and loading at the same time, and the receiving end was not specified...

Try this code and see if it works...  If not, you will have to be abit more specific on 'the variables aren't populating the dynamic text fields' part cuz I don't really understand that...

CyanBlue
mcvars.sendAndLoad("stats2.cfm?ID=" + _root.user_modelid + "&startrow=" + startrow_number2 + "", mcvars, "GET");

Open in new window

0
 
ComputerGeek96Author Commented:
on the frame "frame_portfolio", there is a movie clip with the name "portfolio_mc".  in that movie clip are dynamic text fields with variables names assigned to them.  The results of the loadvariables was being sent to that mc to populate those fields.  the loadvars isn't sending the variable values to that mc to populate the fields.  Thats where I'm at now.  I need to populate those fields.  seems inefficient to manually do it when the loadvariables did it since it was loading them into that portfolio_mc object.
0
 
CyanBlueCommented:
I totally hear your voice on that...  loadVariables() function gets all the available variables from the external source and place them to whatever is available on the stage whereas you have to manually specify what to display/use with LoadVars() class...  Yes, it does seem abit inefficient, but that's to be more careful on what to use...  For example, you are loading a, b, c, d from the external source, but you only want to use a and c from that...  loadVariables() will replace a, b, c and d alltogether because you have no way to specify what to use and what not to...  That'd be a disadvantage, right???  Well...  That's just one example I can show you why you should not really use loadVariable() function...

CyanBlue
0
 
ComputerGeek96Author Commented:
that makes perfect sense.  it would be much better if there was a loadvariables method that waited until all the data was loaded then ran the function similar to the onLoad method.  the onData method doesn't seem to wait for all the data.  unless I am missing something.  I need to see if the client wants to invest in anymore later then I'll com back to this thread.  you have been very helpful...I'm not closing this out just yet.
0
 
CyanBlueCommented:
No, the onData won't work well with loadVariables() function...  You need to create an onEnterFrame loop to wait until you get the data, and then do whatever is needed...  

CyanBlue
0
 
ComputerGeek96Author Commented:
while I check with the client, could you give me more information on the onEnterFrame thing??  i just want to gauge if it will be faster than redoing the stuff with the loadvars and onLoad.
0
 
ComputerGeek96Author Commented:
I don't disagree with using loadVars part, I have to keep in mind what the client will pay for...to do it right or do it quick.  So the onEnterFrame is a loop or do i need something that keeps making it loop??
0
 
CyanBlueCommented:
Oh, I totally hear you on that...  ;)

onEnterFrame is the loop...

CyanBlue
0
 
CyanBlueCommented:
Any update???

CyanBlue
0
 
ComputerGeek96Author Commented:
Admins, please don't close this thread yet.  I am still waiting for a reply back from the client on if they want me to proceed.
0
 
CyanBlueCommented:
Any update???

CyanBlue
0
 
ComputerGeek96Author Commented:
hehe...sorry....my client hasn't given me the go or no go yet.
0
 
CyanBlueCommented:
I guess you haven't heard from your client after 1 month???  :p

CyanBlue
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.