dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: useing Arrays

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    109

    useing Arrays

    when an Array is passed in to flash, say a name like 'totalgames'. using the sendAndLoad , how do you see whats in it?

  2. #2
    Waaambulance Pilot sk8Krog's Avatar
    Join Date
    Apr 2001
    Location
    moo york city
    Posts
    1,980
    you can do someting like
    Code:
    for (i = 0; i < array.length; i++) {
      trace(array[i]);
    }
    where array is replaced with the array name. this should work if tested inside flash, that way the trace function can output the stuff.
    It must be obvious day at camp stupid

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    109

    ok

    well I tried that but it doesn't work. So I am now tryin g to send VAR with a string. Then I can break it up as needed.
    I am sending the current month to a PHP scriipt and want it return the events for that month. so I sendAndLoad 'month_id' and then get back 'totalevents'. so does that totalevents have to be a string or can it be a Array? I have heard that t can't but wanted to find out from here. Also could you please give an example as to how this would work, like":
    Code:
    sendData = new LoadVars();
    sendData.month_id = "month";
    sendData.onLoad = function (success) {
     if (success) {
     trace("Good job!");
    }else{
     trace("oops!");
    }
    sendData.sendAndLoad("website/file.php",sendData,"POST");
    }
    So what I need to know is how to access this data, I have done this already for single variables BTW.

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    You have to send the array as a string, the simplest way to do this is by looping through the array in PHP creating a variable from each element,

    PHP Code:
    $output '';
    for (
    $i 0$i count($arrayName); ++$i) {
        
    $output .= "&arrayVariable$i=" urlencode($arrayName[$i]);
    }
    echo 
    $output
    when loaded by flash this will create variables, arrayVariable0, arrayVariable1 etc in your loadvars object whch can be accessed like,

    code:

    sendData = new LoadVars();
    sendData.month_id = "month";
    sendData.onLoad = function(success) {
    if (success) {
    var i = 0;
    while (this["arrayVariable" + i] != undefined) {
    trace(this["arrayVariable" + i]);
    ++i;
    }
    }
    }
    sendData.sendAndLoad("website/file.php", sendData, "POST");


  5. #5
    Senior Member
    Join Date
    Apr 2001
    Posts
    109

    Dang it

    stil not workign

    Code:
    
    sendData = new LoadVars();
    // I need to send the month and year as follows
    sendData.month_id = "05/03";
    sendData.onLoad = function(success) {
            if (success) {
    			trace("It works");
    		                    var i = 0; 
                    while (this["totaldates" + i] != undefined) {
                            trace(this["totaldates" + i]);
                            ++i;
                    
    				}
            }
    }
    sendData.sendAndLoad("http://members.lycos.co.uk/robot4hire/monthinfo.php", sendData, "POST");
    Here is alittle PHP code
    Code:
    $totaldates = "";
    $i = 0;
    
    if ($month_id != "") {
    	list($md,$yd) = explode("/", $month_id);
    	$query = "select * from sqn_db";
    	$result = query($query, $connection);
    	while ($row = mysql_fetch_array($result)) {
    		$mdate = $row['Date'];
    		$mid = $row['id'];
    
    		list($m,$d,$y) = explode("/", $mdate);
    
    		if ($m == $md && $y == $yd) {
    			$totaldates[] = $d;
    
    						$i++;
    		}
    	}
    	for ($i = 0; $i < count($totaldates); ++$i) {
    		
    		$totaldates .= "&day$i=" . urlencode($totaldates[$i]);
    	}	
    }
    echo $totaldates;
     
    
    ?>
    Now this should output something in the output window yes?

  6. #6
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    try this PHP,

    PHP Code:
    <?php
    // connect to database first

    $totalDates = array();
    $output '';

    if (isset(
    $_POST['month_id'])) { // check the month_id variable was sent, use $HTTP_POST_VARS instead of $_POST in older versions of PHP
        
    list($md$yd) = explode('/'$_POST['month_id']);

        
    $query "SELECT * FROM sqn_db";
        
    $result mysql_query($query$connection);
        while (
    $row mysql_fetch_assoc($result)) { // mysql_fetch_assoc is more efficient than mysql_fetch_array
            
    $mDate $row['date'];
            
    $mId $row['id']; // is the id needed? it isn't used here, though it could easily be added to the output if you need it

            
    list($m$d$y) = explode('/'$mDate);
            if (
    $m == $md && $y == $yd) {
                
    $totalDates[] = $d// add the day to the totalDates array
            
    }
        }
        
    // loop through $totalDates adding the contents to the variable $output
        
    for ($i 0$i count($totalDates); ++$i) {
            
    $output .= "&day$i=" urlencode($totalDates[$i]);
        }
        echo 
    $output;
    }
    sample ouput, if your mdate field contained 4 rows,

    date
    ------
    05/12/03
    05/17/03
    05/22/03
    06/01/03

    and the month_id variable was 05/03 the output from the script would be,

    &day0=12&day1=17&day2=22

    that is a list of variables day0, day1, day2 containing the days in the month that have an event taking place.

    in flash you can access these using,

    code:

    sendData = new LoadVars();
    sendData.month_id = "05/03";
    sendData.onLoad = function(success) {
    if (success) {
    var i = 0;
    while (this["day" + i] != undefined) {
    trace(this["day" + i]);
    ++i;
    }
    }
    }
    sendData.sendAndLoad("http://members.lycos.co.uk/robot4hire/monthinfo.php", sendData, "POST");


  7. #7
    Senior Member
    Join Date
    Apr 2001
    Posts
    109

    THANK YOU!

    Ok that is working, But I am using Lycos hosting with stupid adds on everypge that I use. If you try this script it loads the first date (10) but then instead of the next date (17) it loads the Javascript stuff from those ads : (
    any ideas? Here is the movie.
    HTML page
    Download FLA

    Thank you for all you help!
    Andrue

  8. #8
    Senior Member
    Join Date
    Apr 2001
    Posts
    109

    THANK YOU!

    Ok that is working, But I am using Lycos hosting with stupid adds on everypge that I use. If you try this script it loads the first date (10) but then instead of the next date (17) it loads the Javascript stuff from those ads : (
    any ideas? Here is the movie.
    HTML page
    Download FLA
    It may take a sec to load the data, It's free webhosting : )

    Thank you for all you help!
    Andrue

  9. #9
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hmm, that is a problem. I can't think of a way to get round the web hosts inserting their own code in the middle of your scripts output (beyond finding better web hosts that is, sorry) maybe you could try lycos' tech support, they might be able to help you out.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center