Flint Particle System Forum - Removing initializers 2011-12-11T04:56:22+00:00 http://flintparticles.org/forum/ Lussumo Vanilla & Feed Publisher Removing initializers http://flintparticles.org/forum/comments.php?DiscussionID=367&Focus=1239#Comment_1239 2010-06-23T21:59:40+01:00 2010-07-01T07:57:37+01:00 rrh http://flintparticles.org/forum/account.php?u=379 Why isn't this removing all the initializers? var tempList:Array = emit.initializers; for (var i:int=0;i
var tempList:Array = emit.initializers;
for (var i:int=0;i<tempList.length;i++) {
emit.removeInitializer(Initializer(tempList[i]));
}

trace(emit.initializers.length);


That trace at the end keeps tracing 3 or 4, but if it's removing the initializers, I'd expect it to be 0. Does removeInitializer not remove the intializer from the linitializers array?]]>
Removing initializers http://flintparticles.org/forum/comments.php?DiscussionID=367&Focus=1240#Comment_1240 2010-06-24T23:40:56+01:00 2010-07-01T07:58:00+01:00 rrh http://flintparticles.org/forum/account.php?u=379 For context, the purpose of this is I'm doing something where I need to change the initializer properties a lot, and if I keep going: emit.addInitializer( new ScaleImageInit( scale*0.25, scale ) ...
emit.addInitializer( new ScaleImageInit( scale*0.25, scale ) );
emit.addInitializer( new ColorInit( colour ) );


What happens to the old initializers? I figured, hey, the easy solution is to just remove the old initializers before I add the new ones, but whatever I do, I want to be sure I'm not creating a memory leak.]]>
Removing initializers http://flintparticles.org/forum/comments.php?DiscussionID=367&Focus=1241#Comment_1241 2010-07-01T07:57:07+01:00 2011-12-11T04:56:22+00:00 Richard http://flintparticles.org/forum/account.php?u=1 Because tempList is not a copy of the initializers array, it is the initializers array. As a result, tempList.length reduces by one every time around the loop and you miss some of the ...
There are a number of other ways you could do this that would work. Here's three of them...

var tempList : Array = emit.initializers.slice();
for ( var i : int = 0; i < tempList.length; i++ )
{
emit.removeInitializer( Initializer( tempList[i] ) );
}


for ( var i : int = emit.initializers.length - 1; i >= 0; i-- )
{
emit.removeInitializer( Initializer( emit.initializers[i] ) );
}


while ( emit.initializers.length > 0 )
{
emit.removeInitializer( Initializer( emit.initializers[0] ) );
}
]]>
Removing initializers http://flintparticles.org/forum/comments.php?DiscussionID=367&Focus=1243#Comment_1243 2010-07-05T16:58:05+01:00 2011-12-11T04:56:22+00:00 Xor http://flintparticles.org/forum/account.php?u=381 If you don't need to actually remove or add new initializers, then you can also save reference to the initializer and then directly change the values on it as you go. This way you don't need to ...
var colorInit :ColorInit = new ColorInit( colour );
emit.addInitializer( colorInit );

// later
colorInit.minColor = 0xFFFFFF;
]]>