PDA

View Full Version : Script slows down and freezes


wowxp
03-08-2010, 02:23 PM
Hello guys i am not an expert (or close to that) in AS. I had to write a script that pulls image names out of a mysql database and load them into a flash. It's some kind of slide show, 2 movie clips objects that go from left to right and when one reaches the end of the main frame borders then go back to starting position, change its picture and go from left to right again. I think that problem might be some memory leak (from the Loader). Please help me!

import flash.display.Sprite;
import flash.system.System;
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.net.Responder;
import flash.utils.describeType;
import flash.net.URLRequest;

var idx = 0;
var max = 6;

var gatewayURL:String = "http://mysite.com/jom/amfphp/gateway.php";
var connection:NetConnection;
var aArr:Array = new Array();


connection = new NetConnection();
connection.objectEncoding = ObjectEncoding.AMF0;
connection.connect(gatewayURL);
connection.call("FetchImages.Banner1", new Responder(onResult, onFault));
connection.close();

function onResult(evt:Object):void
{
var values:Array = evt.serverInfo.initialData;
var category:Array = evt.serverInfo.columnNames;

for (var i:Number=0; i < values.length; i++) {
aArr[i] = new Object();
for (var aIndex:* in category) {
aArr[i][category[aIndex]] = values[i][aIndex];
}
}


if(aArr.length < max) max = aArr.length;
if(aArr.length != 0){
cpic(pic1);
cpic(pic2);
addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
}
}

function onFault(obj:Object):void
{
//do nothing
}


function onLoop(evt:Event):void{
pic1.x -= 2.6;
pic2.x -= 2.6;

if(pic1.x <= -140){
pic1.x = 320;
cpic(pic1);
}
if(pic2.x <= -140){
pic2.x = 320;
cpic(pic2);
}
}

function cpic(d):void{
var rect:Shape = new Shape();
rect.graphics.beginFill(0xFFFFFF);
rect.graphics.drawRect(0, 0, 142, 298);
rect.graphics.endFill();
d.addChild(rect);


var ldr:Loader = new Loader();
var urlReq:URLRequest = new URLRequest('http://mysite.com/images/asiahair/thumbs/'+aArr[idx]['image_file']);
ldr.load(urlReq);
d.addChild(ldr);
//ldr.unload();
ldr.unloadAndStop();
if((max - 1) == idx){
idx = 0;
}else{
idx++;
}
}

wowxp
03-10-2010, 07:03 AM
help :confused:

ASWC
03-10-2010, 12:55 PM
[moderator] it would help if you post your questions to the right forum. NetConnection works with FMS or in AIR so your thread shouldn't be in the AS3 forum. Moving your thread now to FMS forum.

sparkdemon
03-14-2010, 02:45 PM
Ok shoot your problem ? :) what you want to do in your program... ?

wowxp
03-15-2010, 04:04 PM
Here's working example - http://stanxp.com/jom/ (all 3 flashes uses almost same code, they pull data from mysql then load the images, you can see it in the code). But after a while (1+ hour) it starts lagging when image is loaded and browser eventually crashes.