kottore / away3d

Automatically exported from code.google.com/p/away3d
0 stars 0 forks source link

more r-elements than t-elements ? #57

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
How can it that there are more r elements dan t elements?

To reconstruct the situation just copy this code:

import away3d.primitives.*;
import away3d.containers.*;
import away3d.core.base.Object3D;
import flash.events.*;
import flash.system.System;
import flash.utils.Dictionary;

var dic:Dictionary = new Dictionary(true);

var _scene:Scene3D = new Scene3D();         
dic['view'] = new View3D({stats:true, scene:_scene, x:stage.stageWidth/2,
y:stage.stageHeight/2});//stats: false, renderer:basicrenderer
dic['view'].scene=_scene;
addChild(dic['view']);

for (var i=0; i<30; i++)
    _scene.addChild(new Sphere({material:'red', segmentsW:20, segmentsH:20,
ownCanvas:true}));

stage.addEventListener(Event.ENTER_FRAME, enterframe);
stage.addEventListener(MouseEvent.CLICK, klik);

function enterframe(e:Event)
{
    dic['view'].render();
}

function klik(e:Event)
{
    for (var j:int = 0; j < _scene.children.length; j++)
    {
        _scene.children[j].ownCanvas = false;
        _scene.removeChild(_scene.children[j]);
    }
    System.gc();
}

Let me now what you think about this! And if you also have more r-elements
than t-elements. Maybe i am doing something wrong, just tell me ;)
Ow and the for (var j:int = 0; j < _scene.children.length; j++) - loop
doesn't go further then 15, am i doing something wrong here?

Sam

Original issue reported on code.google.com by samoverd...@gmail.com on 24 Aug 2009 at 4:31

GoogleCodeExporter commented 8 years ago
the for loop problem. the problem occurs everywhere. if a add 30 sphere, and 
remove
them with the for loop then the loop loops through 50%.
first loop, 30 objects -> remove 15
second loop, 15 objects -> remove 8
thrid loop, 7 objects -> remove 4
fourth loop, 4 objects -> remove 2
fifth loop, 2 objects -> remove 1
sixth loop, 1 object -> remove 1

i don't understand, am i the only one with this problem?

Original comment by samoverd...@gmail.com on 27 Aug 2009 at 1:22

GoogleCodeExporter commented 8 years ago
the problem here is that you are removing children at the start of the array. 
this
causes the remaining children to shuffle along by one. but in the next loop, 
you have
incremented your index by one! so yes, this way will strip every other child 
object
in the loop. if you want to remove all children without this problem, you should
iterate your index value from the end of the array, so that no objects are 
shuffled
along.

Original comment by rob.bate...@gmail.com on 15 Sep 2009 at 11:21