PDA

View Full Version : Help Remoting Array


designlevel2
03-24-2004, 01:44 PM
Ok I have a remoting project that needs to load about 50 images per swf. I have the whole thing working, but now im running into preloading issues.

That being said I am readdressing how to achieve this. I think what I need to do is bring all of the file names into a local array, then use setInterval to load them. I have this working fine statically but when I populate the array with remoting it screws up and doesnt work. My question is how do I populate an array locally. Here's my static code that does work:

k=0;
myDummyArray = ['images/naveen.jpg', 'images/cn4.jpg', 'images/mu_med.jpg', 'images/rb_med.jpg'];
i = 0;
//ArrayAll = (myDummyArray[0]+", "+myDummyArray[1]+", "+myDummyArray[2]);
ArrayAll = (myDummyArray[0]+", "+myDummyArray[1]+", "+myDummyArray[2]+", "+myDummyArray[3]+", "+myDummyArray[4]);

totaljpgs = 4;
for(i=0;i<=totaljpgs;i++){
rclip=_root.createEmptyMovieClip("MyClip"+i,i);
rclip.loadMovie(myDummyArray[i]);
rclip._x = (100*i);
rclip._y = 300;
//rclip.loadMovie("images/cn1.jpg");
}


function loadtotalfunction(){
for(i=1;i<=totaljpgs;i++){
total=_root["MyClip"+i].getBytesTotal();
//}
//clearInterval(loadtotalinterval);
preloadinterval=setInterval(preloadfunction,10);
}
}
function preloadfunction(){
for(i=1;i<=totaljpgs;i++){
loaded=_root["MyClip"+i].getBytesLoaded();
}
fractionloaded=(loaded/total);
//percentloaded=loaded;
if (fractionloaded>0){
percentloaded=math.floor(100*fractionloaded)+" %";
}
if(fractionloaded>=1){
clearInterval(preloadinterval);
}
}
loadtotalinterval=setInterval(loadtotalfunction,10 );


Thanks in advance.

petefs
04-13-2004, 06:28 PM
I would use the mc loader class available in either flash 7 or the flash 6 version located at this url:
Colin Moock's loading class (http://www.moock.org/blog/archives/000010.html)

assuming you have your flash service set up to just:
return mysql_query("select image_url from images");

flash 6 example:

#include "NetDebug.as"
#include "NetServices.as"
#include "DataGlue.as"
#include "com.qlod.LoaderClass.as"

imgLoader = new com.qlod.LoaderClass();
imgLoadProgress = new Object();

responder = new Object();
gatewayurl = "http://yourdomain/flashservices/gateway.php";
NetServices.setDefaultGatewayUrl(gatewayurl);
connection = NetServices.createGatewayConnection();
MyService = connection.getService("MyService", responder);
MyService.getImages();

responder.getImages_Result = function(data)
{
totalImages = data.getLength();
loadedImages = 0;
for(var i=0;i<data.getLength();i++){
var _mc = createEmptyMovieClip("img"+i, 100+i);
imgLoader.load(_mc, data.items[i].img_url, imgLoadProgress);
}
}

imgLoadProgress.onLoadProgress = function (loaderObj)
{
trace(loaderObj.getPercent());
}

that should load each returned url sequentially, you can handle how you place them however you want. if you want each movieclip to have it's own preloader going, the documentation at the URL for the loader above will illustrate how to do that rather easily. I think that's the simplest way to do it, personally. the loader class takes care of all the little weird things that can happen that are a pain in the ay ess ess to debug sometimes ^_^ If you have any other questions lemme know, I can put together a sample webservice and .FLA if that doesn't do it for you.

pete

designlevel2
04-14-2004, 08:28 AM
Thing is I have 11 images in each row of the database. Makes .length kind of a mute point. But I see what you're saying. Ill give it a try later this week.

petefs
04-14-2004, 12:26 PM
If you get a chance, could you post either some real data or some test data from your database as INSERT statements (assuming it's mysql)? or just give me a good idea of how it's laid out. I would build the array in whatever language you're using to parse AMF data and then pass it to flash -- flash's array manipulation, math, etc...is rather slow comparitavely, it's best to do all the work and pass the data all pretty-like to flash ^_^

something in your webservice like (amfphp):

$image_array = array();
$image_query = mysql_query("select * from images");
while($image=mysql_fetch_array($image_query)){
$image_array[] = $image['row1'];
$image_array[] = $image['row2'];
...
}
return array("image_array" => $image_array);

and then on the flash side:

for(var i=0;i<data.image_array.length;i++){
}

should do it. if things don't work out right post up some test data from the database, otherwise good luck!