Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How can i detect null array values??

    Hi all.

    I am new at flash action script and i have been trying to write a code for an island guide. I have all my data in an XML and I am trying to parse them in flash. Everything is ok with the texts but i have a problem with an arry variable that i have for the filepath of the photos that will be used for each island...

    I found a "photo holder" script from "flashmo" and i modded it for my case and I am trying to determine the length of the array so that it only brings up as many "photo holders" as the picture paths given in the XML. But i can't seem to distiguish between the filled "ISLAND_PHOTO" atributes of the XML and the empty ones... I have tried "!=null", "!=undefined", even deliberately puting in some text to dermine the empty ones like "empty" and then trying a "!="emtpy"" or any other text or number but still i can not seperate them...

    here is the XML "about.xml":


    Code:
    <?xml version="1.0" encoding="utf8"?>
    <ABOUT>
    	<ISLAND>
    		<ISLAND_NAME>Myconos</ISLAND_NAME>
    		<ISLAND_DESCR>descr descr descr</ISLAND_DESCR>
    		<ACTIVITIES>something something something</ACTIVITIES>
    		<EXCURSIONS>bla bla bla</EXCURSIONS>
    		<ISLAND_PHOTOS>
    			<ISLAND_PHOTO>\MYCONOS\MYC_PIC_1.JPG</ISLAND_PHOTO>
    			<ISLAND_PHOTO>\MYCONOS\MYC_PIC_2.JPG</ISLAND_PHOTO>
    			<ISLAND_PHOTO>\MYCONOS\MYC_PIC_3.JPG</ISLAND_PHOTO>
    			<ISLAND_PHOTO></ISLAND_PHOTO>
    			<ISLAND_PHOTO></ISLAND_PHOTO>
    			<ISLAND_PHOTO></ISLAND_PHOTO>
    			<ISLAND_PHOTO></ISLAND_PHOTO>
    			<ISLAND_PHOTO></ISLAND_PHOTO>
    			<ISLAND_PHOTO></ISLAND_PHOTO>
    			<ISLAND_PHOTO></ISLAND_PHOTO>
    		</ISLAND_PHOTOS>
    	</ISLAND>
    </ABOUT>

    and the part of the script that i have a problem with:


    Code:
    var xml_file:String = "about.xml";
    var folder:String = "thumbnails/";
    var MY_PIC:Array = new Array();
    var total:Number;
    var i:Number;
    var xml:XML = new XML();
    xml.onLoad = function() {
    	item_list.fm_item._visible = false;
    	var nodes = this.firstChild.firstChild.lastChild.childNodes;
    	total = nodes.length;
    
    	for (i=0; i<total; i++) {
    		if (nodes[i] != null); 
    		{
    			MY_PIC[i] = nodes[i].childNodes;
    		}
    	}
    
    	create_item_list();
    };
    xml.load(xml_file);
    xml.ignoreWhite = true;
    
    function create_item_list():Void {
    	for (i=0; i<MY_PIC.length; i++) {
    		var item = flashmo_item.duplicateMovieClip("fm_item"+i, i);
    		item.fm_pic.loadMovie(folder+MY_PIC[i]);
    		item._x = i*320;
    
    	}
    The script should just dublicate a "photo holder" (actually called "fm_item" in the script) function for as many times as the MY_PIC.length... but that is allways 10.. as many as I have reserved in the XML... The script reads them all as not null... It works fine for the 3 paths that are defined and gives me an output of :


    Code:
    Error opening URL 'file:///C|/Users/user/Desktop/thumbnails/'

    for the "ISLAND_PHOTO" atributes that don't have a path in them.

    Any help would be greatly apricated... I have been looking at that script and trying out different solutions for a few days now, and i am not any closer to making it work the way i want it to...
    Last edited by alobarn; 03-25-2009 at 06:29 PM. Reason: rephrasing

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Well it makes more sense to remove the extra code from the xml file, why not?

    Code:
    for (i=0; i<total; i++) {
    if (nodes[i] != "")
    {
    MY_PIC[i] = nodes[i].childNodes;
    }
    }
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    first of all thanks for the reply...

    I can't remove the extra fields, because some islands might have 3 pics, some 10 and some none... i am building the xml out of a mysql database with some php code and i can't have a set number of pics.. it depends on each island...

    and as for the empty quotes ("") i have tried it and it doesn't work either...


    any other ideas?

  • #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Why can't you make it scale? I see no reason that you couldn't have 20 images in one album and 3 in the next, just generate the XML and let Flash create as many containers as needed.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #5
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    that's what i am trying to do with that script... and that's what it should be doing as it is now, no?

    are you saying that i should be looking at the xml generator script and not the flash script? put some code there to check for data before generating the xml? I will give that a try...

    it is weird though that flash cannot separate between the empty nodes and the ones with data, no?

  • #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Well can you post the PHP? You are still parsing extra loops because of the blank nodes.

    It can separate it out I'm sure, but I can't test anything since I don't have flash on this computer right now. Try this,

    Code:
    trace(MY_PIC[i]);
    right after you set MY_PIC in the loop. It should output the value, and see if the blank nodes are given a value which you can use to check against.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • #7
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    again thanks for the relpy..

    i have tried tracing everything... from the MY_PIC.length to every MY_PIC even to every variable in the script...

    the trace in every loop is just an empty line.. the first 3 are the paths that i have set in the xml and then it just takes it down a line...

    And then it starts outputing the url errors..

    Which come to think of it gives me an idea.. what if it reads them as pagebreaks or enter? how could i check for pagebreaks or enter? != what?

    as for the php i'm working on a "if loop" to check the value before puting them in the xml...

    but here is the original version just for your reference..

    PHP Code:
    <?php
    header
    ("Content-type: text/xml"); 


    include 
    'dat.php';
    // Connect to server and select databse.
    $linkID mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db($db_name$linkID)or die("cannot select DB");
     
    $query "SELECT * FROM $tbl_name";
    $resultID mysql_query($query$linkID) or die("Data not found.");

    $xml_output "<?xml version=\"1.0\" encoding=\"utf8\"?>\n";
    $xml_output .= "<ABOUT>\n";

    for(
    $x $x mysql_num_rows($resultID) ; $x++){
        
    $row mysql_fetch_assoc($resultID);
        
    $xml_output .= "\t<ISLAND>\n";
        
    $xml_output .= "\t\t<ISLAND_NAME>" $row['ISLAND_NAME'] . "</ISLAND_NAME>\n";
        
    $xml_output .= "\t\t<ISLAND_DESCR>" $row['ISLAND_DESCR'] . "</ISLAND_DESCR>\n";
        
    $xml_output .= "\t\t<ACTIVITIES>" $row['ACTIVITIES'] . "</ACTIVITIES>\n";
        
    $xml_output .= "\t\t<EXCURSIONS>" $row['EXCURSIONS'] . "</EXCURSIONS>\n";
        
    $xml_output .= "\t\t<ISLAND_PHOTOS>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_1>" $row['ISLAND_PHOTO_1'] . "</ISLAND_PHOTO_1>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_2>" $row['ISLAND_PHOTO_2'] . "</ISLAND_PHOTO_2>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_3>" $row['ISLAND_PHOTO_3'] . "</ISLAND_PHOTO_3>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_4>" $row['ISLAND_PHOTO_4'] . "</ISLAND_PHOTO_4>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_5>" $row['ISLAND_PHOTO_5'] . "</ISLAND_PHOTO_5>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_6>" $row['ISLAND_PHOTO_6'] . "</ISLAND_PHOTO_6>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_7>" $row['ISLAND_PHOTO_7'] . "</ISLAND_PHOTO_7>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_8>" $row['ISLAND_PHOTO_8'] . "</ISLAND_PHOTO_8>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_9>" $row['ISLAND_PHOTO_9'] . "</ISLAND_PHOTO_9>\n";
        
    $xml_output .= "\t\t\t<ISLAND_PHOTO_10>" $row['ISLAND_PHOTO_10'] . "</ISLAND_PHOTO_10>\n";
        
    $xml_output .= "\t</ISLAND_PHOTOS>\n";
        
    $xml_output .= "\t</ISLAND>\n";
    }

    $xml_output .= "</ABOUT>";

    $filenamepath =  "about.xml";
     
     
    $fp fopen($filenamepath,'w');

                
    fwrite($fp,$xml_output);
                
    fclose($filenamepath);
     
     echo 
    $xml_output

    ?>
    I'll post the new php when i manage to finish it..
    Last edited by alobarn; 03-25-2009 at 06:31 PM. Reason: adding text

  • #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    PHP Code:
    <?php
    header
    ("Content-type: text/xml"); 


    include 
    'dat.php';
    // Connect to server and select databse.
    $linkID mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db($db_name$linkID)or die("cannot select DB");
     
    $query "SELECT * FROM $tbl_name";
    $resultID mysql_query($query$linkID) or die("Data not found.");

    $xml_output "<?xml version=\"1.0\" encoding=\"utf8\"?>\n";
    $xml_output .= "<ABOUT>\n";

    for(
    $x $x mysql_num_rows($resultID) ; $x++){
        
    $row mysql_fetch_assoc($resultID);
        
    $xml_output .= "\t<ISLAND>\n";
        
    $xml_output .= "\t\t<ISLAND_NAME>" $row['ISLAND_NAME'] . "</ISLAND_NAME>\n";
        
    $xml_output .= "\t\t<ISLAND_DESCR>" $row['ISLAND_DESCR'] . "</ISLAND_DESCR>\n";
        
    $xml_output .= "\t\t<ACTIVITIES>" $row['ACTIVITIES'] . "</ACTIVITIES>\n";
        
    $xml_output .= "\t\t<EXCURSIONS>" $row['EXCURSIONS'] . "</EXCURSIONS>\n";
        
    $xml_output .= "\t\t<ISLAND_PHOTOS>\n";

    for (
    $z=0;$z<10;$z++;)
    {
      
    $xml_line "ISLAND_PHOTO_$z";
      if (
    $row["$xml_line"] != "") {
      
    $xml_output .= "\t\t\t<$xml_line>" $row["$xml_line"] . "</$xml_line>\n";
      }
    }

        
    $xml_output .= "\t</ISLAND_PHOTOS>\n";
        
    $xml_output .= "\t</ISLAND>\n";
    }

    $xml_output .= "</ABOUT>";

    $filenamepath =  "about.xml";
     
     
    $fp fopen($filenamepath,'w');

                
    fwrite($fp,$xml_output);
                
    fclose($filenamepath);
     
     echo 
    $xml_output

    ?>
    Try this or something close to it
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  • Users who have thanked gnomeontherun for this post:

    alobarn (03-27-2009)

  • #9
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    IT WORKS!

    apart from an extra semicolomn at the statement of the variables... ($z++; should just be $z++) everything esle is ok.

    what i wanted to do is being done... maybe we couldn't find the problem with the action script, but the workaround with the php does exactly the same job...

    thank you very much for your help!!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •