Groups | Blog | Home
all groups > flash data integration > february 2007 >

flash data integration : Browsing loaded images


thahip
2/21/2007 6:25:33 PM
Hi,

I am loading images from a mysql database. Lets say I was displaying 8 on a
page, how can I tell how many pages I have and have it update when more images
are added?

Like on sites where they have links like

images 1-12 | 13-25 | 26-38 | 39-51 etc

thanks

Gavin
MotionMaker
2/22/2007 12:00:00 AM
Your server script would need to use SQL to get a count on the table holding
the image data each time the user selects a new image in Flash. Then send that
data back. Then Flash would reconfigure the user interface should the count
change. This creates some interesting programming challenges is something like
the user is viewing 39-51 and on the next view the server now reports only 20
images.

The bigger question is about design: "when should the app request the data
that configures the image counts? "Once on app launch, based on a timer
interval, when the user interacts with image selections as mentioned above,
provide the user a refresh interaction.
thahip
2/22/2007 3:01:52 PM
Hi,

I have looked at the count sql function, and this looks like it will be
useful, however my coding knowledge is not high.

At present this sort of code is being used to access the database and also the
flash to display it.

<?php
$connect = mysql_connect("localhost", "user", "pass");
mysql_select_db("database_name", $connect);
$result = mysql_query("SELECT Title, Comments, Image FROM titles");
$cant = 0;
while($row=mysql_fetch_array($result)){
echo
"Title$cant=$row[Title]&Comments$cant=$row[Comments]&Image$cant=$row[Image]&";
$cant++;
}
echo "cant=$cant";
?>

Actionscript -

//Create LoadVars object and load file
myData = new LoadVars()
myData.load("file_name.php") //php line
myData.ref = this
//Fetch data
myData.onLoad = function(succes){
if(succes){
for(var i=0; i<this.cant; i++){
this.ref["Title_txt"+i].htmlText = "[B]"+this["Title"+i]+"[/B]"
this.ref["Comments_txt"+i].text = this["Comments"+i]
this.ref["holder_mc"+i].loadMovie(this["Image"+i])
}
} else trace("Error loading data");
}

Any ideas on how to approach the problem, and any useful links would be great

thanks

Gavin
MotionMaker
2/22/2007 3:39:20 PM
Send the total row count back and on the AS side you need to do math to
determine what number of views you have. If you show 12 images, the divide the
total row count by 12 and if you have a remainder add 1 to get the total views.
In this case view 1 is always 1-12 and view 2 is always 13-25.

PHP



$numrows = mysql_num_rows($result);

echo "cant=$cant&count=$numrows";
AddThis Social Bookmark Button