Loading xml from php prob - actionscript2.0

Hey there,

Im going mad for 2 days now. ive got a php file which call the swf -> send a variable which the swf takes and send it back to the php -using sendAndLoadVars (which is the routing to the images folder). the php reads it (openddir etc…) then start creating the xml.

When the var has been successfuly sent back from php, it must call a function to load the xml. It does the trick but it does not read my children which is created via a for each in the php. It looks like the flash reads or get the var back before the php has fully created the xml. here the code:


//php

if(isset($_GET['filedir'])){ ///////THIS IS THE VAR SENT FROM FLASH //////
    $file_dir = $_GET['filedir'];
    $dir=opendir("../../" . $file_dir);

    while (false !== ($file = readdir($dir)))//$file=readdir($dir) wrong way of reading
    {
        $ext = substr($file, strpos($file, ".")+1);
    
        if(array_search($file, $exclude_files)===false && array_search($ext, $allowed_formats)!==false){
            $f=$file_dir.'/'.$file;    
            $path []=$f;
        }
    }

    closedir($dir);
    
}


$directory= $_SERVER['PHP_SELF'];
$directory=dirname($directory);

//Removing words from modules
if($p = strpos($directory, "modules/")){
    $directory = substr($directory, 0, $p);
}

$galleryBgColor = "0x00ffff";

echo "<?xml version='1.0' encoding='iso-8859-1'?>
";

echo "<gallery_thumbs>
";
echo "<gallerySetUp>
";
echo "    <setUp bgColors=\"" .$galleryBgColor ."\"/>
";
echo "</gallerySetUp>
";
echo "<galleryBig>
";

///THE 4 CHILD HERE ARE BEING READ AND DISPLAYED BUT AS SOON AS I ENABLE THE FOREACH THERE IS NO CHILDREN IN THE GALLERYBIG

echo "    <galleryPic location='http://localhost/yousemble_demo/images/flashgallery/gallery_001/002.jpg' />
";
echo "    <galleryPic location='http://localhost/yousemble_demo/images/flashgallery/gallery_001/004.jpg' />
";
echo "    <galleryPic location='http://localhost/yousemble_demo/images/flashgallery/gallery_001/005.jpg' />
";
echo "    <galleryPic location='http://localhost/yousemble_demo/images/flashgallery/gallery_001/003.jpg' />
";




    //foreach ($path as $val) echo '<pic src="'.'http://'.$directory.'/'.$val.'" title="" />';;
    /* foreach ($path as $val) {
        echo "    <galleryPic location='http://localhost/yousemble_demo/images/flashgallery/gallery_001/003.jpg' />
";
    } */
        
echo "</galleryBig>
";
echo "</gallery_thumbs>
";


HOW CAN I TELL FLASH TO READ THE XML WHEN IT IS FULLY CREATED

MY ACTIONSCRIPT



var sendl:LoadVars = new LoadVars();
var receivel:LoadVars = new LoadVars();
    
//build the var to be sent to php
sendl.filedir = picFolder;

receivel.onLoad = function(success):Void {
    /*if(this.toFlash){
        test.testtxt.text = "Checking the php variable" +" "+ this.toFlash;
        //loadXML();
        testGallery()
    }else{
        test.testtxt.text = "not good";
    }*/
    if (success) {
        test.testtxt.text = "trying success";
        loadXML();
    }else{
        test.testtxt.text = "not good";
    }
}

sendl.sendAndLoad(xmlURL,receivel, "GET");



function loadXML():Void {
    var galleryXML = new XML();
    galleryXML.ignoreWhite = true;
    
    galleryXML.onLoad = function(success) {
    
        if (success) {
            trace("fully loaded the xml file");
            test.testtxt.text = "must load the xml" +" "+ picFolder;
            getGalleryPic(galleryXML);
        } else {
            trace("error loading the xml");
        }
        
    }
    
    galleryXML.load(xmlURL);
}



function getGalleryPic(galleryXML){
    
    var gallerySetUp = galleryXML.firstChild.childNodes[0]; //Take the first child of the Parent --- the one holding background color
    var galleryBigImg = galleryXML.firstChild.childNodes[1];
    
    if (gallerySetUp.nodeName == "gallerySetUp") {
        
        for (i=0; i<gallerySetUp.childNodes.length; i++) {
            pageSetUp = gallerySetUp.childNodes*;
            bgColor = (pageSetUp.attributes.bgColors);
        }
        
    }

    //Getting the Big pics from the xml
    test.testtxt.text = galleryBigImg.childNodes.length + " " + picFolder;
    if (galleryBigImg.nodeName == "galleryBig") {
        for (i=0; i<galleryBigImg.childNodes.length; i++) {
            galleryBig = galleryBigImg.childNodes*;            
            galleryBigPic.push(galleryBig.attributes.location);
            //test.testtxt.text = galleryBig.attributes.location;
        }
        
    }
    
    xmlLength = galleryBigPic.length;

    Tweener.addTween(galleryContainer.base,{_color:bgColor, time:0.5, transition:"linear"});

    mustClick = Math.ceil((xmlLength-total)/total);//gives you number of clicks to reach end of length of xml file

    //Show the next and back button if you need them
    if (xmlLength>=updatedCurrent) {
        fwdButton._visible = true;
        bckButton._visible = true;
    } else {
        fwdButton._visible = false;
        bckButton._visible = false;
    }

    //Adjusting the updatedCurrent if it is greater than the xmlLength
    if (updatedCurrent>=xmlLength) {
        updatedCurrent = xmlLength;
    }

    setGallery();
}