;

PDA

Click to See Complete Forum and Search --> : [RESOLVED] RangeError: Error #2006: The supplied index is out of bounds. HELP!!!


peem83
05-25-2009, 06:00 AM
Hi,
I made shared object application with drawing lines, arrow and circles. Almost everything works fine until I restart application.
Not every time but very often I get this error:
RangeError: Error #2006: The supplied index is out of bounds.
This is code which loading share objects:

function addNewChild(data, name) {
var child = null;
switch(data.toolType) {
case "brush":
child = new ScrappyBrush();
break;
case "arrow":
child = new ScrappyLine();
break;
case "text":
child = new ScrappyTxt();
break;
case "textBox":
child = new ScrappyTxtBox();
break;
case "circle":
child = new ScrappyCircle();
break;
case "bitmap":
child = new ScrappyBMP();
break;
}
if (child) {
child.name = name;
dragTarget.addChild(child);
child.updateSharedObject(this.so);
}
}

I was trying to replace dragTarget.addChild(child); to dragTarget.addChildAt(child,0); but that did not solved my problem.

Can anyone explain me what is wrong?

neznein9
05-25-2009, 11:25 AM
I don't see anything in that code that would throw an index error - can you post the full trace when the swf fails? That should show you exactly what function is breaking. (I suspect it's in one of those constructors)

peem83
05-25-2009, 12:30 PM
First thx for replay :)
The problem is that error is only thing what I get. But I was wrong with one thing - replaceing
dragTarget.addChild(child); to
dragTarget.addChildAt(child,0);
solved problem with loading shared objects. Unfortunately the same error message I get during connection with media server (but not every time) . Usually when I draw more objects.
Code to connect and sync with media server:

function mainInit() {
// create a connection to the media server
nc.addEventListener(NetStatusEvent.NET_STATUS,netS tatusHandler);
nc.connect("rtmp://localhost/whiteboard");
this.so = SharedObject.getRemote(args.gidReq+"-"+args.cidReq, nc.uri, true);
this.so.addEventListener(SyncEvent.SYNC,syncEventH andler);
this.so.fps = 0;
this.so.connect(nc);
}

public function netStatusHandler(event:NetStatusEvent):void {
trace(event.info.code);
}

public function syncEventHandler (event:SyncEvent) {
var list = event.changeList;
for (var i = 0; i<list.length; i++) {
if (list[i].name == null) continue;
trace(list[i].name);
if (list[i].code == "delete") {
// Shape has been deleted, remove it.
this.dragTarget.removeChild(this.dragTarget.getChi ldByName(list[i].name));
} else {
var child = this.dragTarget.getChildByName(list[i].name);
if (child)
child.updateSharedObject(this.so);
else
this.addNewChild(this.so.data[list[i].name], list[i].name);
}
}
}

I thought this error concern only addChild function, but I was wrong :(
I'm sure that constructors are ok.
Please give me some idea what can be wrong :(

peem83
05-28-2009, 03:13 AM
Finally I solved that :)
The problem was in function mainInit(), I replace part of the code from this function to the function netStatusHandler
Code:

function mainInit() {
// create a connection to the media server
if(nc == null){
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS,netS tatusHandler);
nc.connect("rtmp://localhost/whiteboard");
}
}

public function netStatusHandler(event:NetStatusEvent):void {
if(event.info.code == "NetConnection.Connect.Success") {
this.so = SharedObject.getRemote(args.gidReq+"-"+args.cidReq, nc.uri, true);
this.so.addEventListener(SyncEvent.SYNC,syncEventH andler);
this.so.connect(nc);
trace(event.info.code);
}
}