Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : wait until php loads



penguinsareinvading
5/30/2004 5:59:45 PM
i have the following actionscript that seems to work well,

var sl = new LoadVars();
sl.load("http://www.site.com/streams/update.php?unique_id="+getTimer());
// this indexes the dir and creates a few XML files that are called later in
the SWF file
// some other stuff
mycomboXml.load("http://www.site.com/streams/mycombodata.xml");
// this returns the un-updated XML data, but if i close the window and open it
again it shows the new data
// i've come to the conclusion that the actionscript doesn't wait for the php
to finish before it continues


i need this all on one frame, so i can't cause it to loop frames until it is
completed...any ideas?
Thanks in advance for any help
BTW I'm not coming here first, i've spent the better part of yesterday
searching and trying things like
var done=false;
var sl = new LoadVars();
while(!done) {
sl.load("http://www.site.com/streams/update.php?unique_id="+getTimer());
}
then adding echo '&done=true';
in my PHP
it caused the SWF to "run slowly" and refuse to load the rest of the movie


thanks again

Jack.
5/30/2004 6:10:08 PM
try using the loadVars onLoad event -

var sl = new LoadVars();
sl.onLoad = function(){ // event fires when php has loaded
mycomboXml.load("http://www.site.com/streams/mycombodata.xml");
};
sl.load("http://www.site.com/streams/update.php?unique_id="+getTimer());

hth

penguinsareinvading
5/30/2004 9:01:50 PM
that might work
penguinsareinvading
5/30/2004 9:14:19 PM
unfortunately, that fails to call my PHP script at all...
here is the full action script of the frame...

//-------for myComboBox-----------
var mycomboXml = new XML();
mycomboXml.onLoad = function(){
var baseName = this.firstChild.childNodes;
var albumName;
var xmlFile;
for(var j=0; j<baseName.length; j++){
if(baseName[j].nodeName != null){
albumName = baseName[j].attributes.albumName;
xmlFile = baseName[j].attributes.xmlFile;
myComboBox.addItem({label:baseName[j].attributes.albumName,
data:baseName[j].attributes.xmlFile});
trace("myalbum for label: " + baseName[j].attributes.albumName + " /for
data: " + baseName[j].attributes.xmlFile);

}//------close if
}//-----close for

}




//the next few lines include files (IMPORTANT)

var sl = new LoadVars();
sl.onLoad = function(){ // event fires when php has loaded
mycomboXml.load("http://www.site.com/streams/mycombodata.xml");
};
sl.load("http://www.site.com/streams/update.php?unique_id="+getTimer());

// all done with important




//--------for listBox------------
myArry = new Array();
xmlName = new XML (); //a flash xml object
xmlName.ignoreWhite = true;
xmlName.onLoad = function ()
{ myListBox.vScrollPolicy = "on";
trace("xmldata loaded success!");
var baseNode = this.firstChild.childNodes;
var mylabel, mydata,link;
for (var i = 0; i < baseNode.length; i++)
{
if (baseNode[i].nodeName != null)
{
mylabel = baseNode[i].attributes.mylabel;
mydata = baseNode[i].attributes.mydata;
myListBox.addItem({label:mylabel,
data:mydata});


//--------------------------output-------------------------
trace("My XmldataList labelList: " + baseNode[i].attributes.mylabel + "
databList: " +baseNode[i].attributes.mydata);
for (var j = 0; j < baseNode[i].childNodes.length; j++)
{
if (baseNode[i].childNodes[j].nodeName == "link")
{
link = baseNode[i].childNodes[j].firstChild.nodeValue;

//myTextList.addItem({label:baseNodes[i].childNodes[j].firstChild.nodeValu
e});
trace("saying:---"+baseNode[i].childNodes[j].firstChild.nodeValue);
}
}
myArray.push(new construct(mylabel, mydata, link));
}
}

for(i=0; i<myArray.length; i++){
//mytitle += "<a href=\"" + myArray[i].link + "\">" + myArray[i].mylabel +
"</a>";
//trace(myArray[i].link);
}

};//-------close xmlName.onLoad function
//function construct(mylabel, mydata, link)
//{
//this.mylabel = mylabel;
//this.mydata = mydata;
//this.link = link;
//}
//-----------myListBox Event-------------
myselection = new Object();
myselection.change = function(ListEvent){
_root.status._visible=1;
myPlayBack.setMedia(myListBox.selectedItem.data,"MP3");
myPlayBack.play(1);
_root.title=myListBox.selectedItem.label;
trace("the selected trackPath: " + myListBox.selectedItem.data);
}
myListBox.addEventListener("change",myselection);
//----------comboBox Event---------
mycomboSelect = new Object();
mycomboSelect.close = function(){
xmlPath="mylistdata.xml";
xmlPath = myComboBox.selectedItem.data;
xmlName.load(xmlPath);
myListBox.removeAll();
myPlayBack.stop();
_root.title="no tracks selected";
_root.status._visible=0;
//mytitle = myComboBox.selectedItem.label;
//mytitlehidden = myComboBox.selectedItem.label+": ";
trace("myAlbumSelection: " + xmlName + "/data: " + xmlPath);
}
myComboBox.addEventListener("close",mycomboSelect);
Jack.
5/30/2004 10:27:34 PM
[quoted text, click to view]

sl = new LoadVars();
sl.onLoad = function(){
trace(unescape(sl)); // do you get any trace here ?
_root.mycomboXml.load("mycombodata.xml");
// path added to scope out of the loadVars object
};
sl.load("update.php");

btw .. earlier you used - echo '&done=true';
you would need to compare to a string in Flash,
if(sl.done =="true")

hth ?
penguinsareinvading
6/1/2004 5:15:54 AM
Jack.
6/1/2004 10:36:02 AM
[quoted text, click to view]

*that* being....??
afraid you've lost me !!
penguinsareinvading
6/1/2004 9:34:44 PM
sorry,
i see how all of those pieces seem to work separately
but i can't combine them all into my AS that i posted earlier, i just don't know how the pieces fit in
Jack.
6/1/2004 10:07:48 PM
what was the answer to -
trace(unescape(sl)); // do you get any trace here ?
is your php loading ?
if so add traces throughout your script to check if
variables are loading, and if so, are they the
variables that you are expecting,
your posted code appears to be okay, bar LoadVars
what results did you get by adding the modified code
i posted ? ( adding your relevant paths, of course :)


AddThis Social Bookmark Button