I'm glad you cleared up exactly what you are attempting to do. I found this
to be a very interesting challenge. 

The goal here was to minimize the amount of processes it will take to
increment a given length at an adjustable stagger. I'm no mathematician but
I haven't seen any problems unless you use 1 or 0 as an increment.  


//
//      VARS
//

        var inx = 0; // CURRENT INDEX
        var len = 10; // LENGTH OF VALUES
        var incr = 3;// STAGGER INCREMENT


//
//      FUNCTION
//

        function update ()
        {
                trace( '\nUPDATE: ' + inx );
                
                for ( var i = inx; i < len; i+= incr ) 
                { 
                        trace( '\t' + i );
                }
                inx += inx < incr-1 ? 1 : -incr+1; 
        }
        onEnterFrame = update;


///////////////////////////////////////////


UPDATE: inx: 0
        i: 0
        i: 3
        i: 6
        i: 9

UPDATE: inx: 1
        i: 1
        i: 4
        i: 7

UPDATE: inx: 2
        i: 2
        i: 5
        i: 8

UPDATE: inx: 0
        i: 0
        i: 3
        i: 6
        i: 9




So as to not throw away hard work, here was my original solution with as
close to what I could assume with the problem before your last post.

It's much like the version above except it doesn't wrap the index, it stores
a reference to any object passed during a current index, and each set has a
lifespan of the WAIT_FRAMES.



curInx = 0;
sets = {};
WAIT_FRAMES = 10;

this.onEnterFrame = runTest;

function runTest()
{
        updateSets (); // update index, remove old sets

        // add new objects
        addObj ( curInx + '_a' );
        addObj ( curInx + '_b' );
        addObj ( curInx + '_c' );
        addObj ( curInx + '_d' );
        addObj ( curInx + '_e' );
}

function updateSets ()
{
        // remove old objects
        removeSet ( curInx - WAIT_FRAMES );

        // increase the index
        curInx++;

        // make an array for the new index
        sets [ '_' + curInx ] = [];

        // debug info
        trace( '\ncurInx: ' + curInx + newline ); }

function addObj ( obj )
{
        // add an object to the current index
        sets [ '_' + curInx ].push ( obj ); }

function removeSet ( inx:Number )
{
        // only remove available sets
        if ( inx < 0 ) return;

        // get set information
        var set = sets[ '_' + inx ];

        // loop through set
        var len = set.length;
        for ( var i = 0; i<len; i++ )
        {
                // get set object
                var obj = set[i];

                // do something to the object
                obj.removeMe ();
                delete set[i];

                // debug info
                trace( 'deleting inx: ' + inx + '  i: ' + i + '   obj: ' +
obj );
        }

        // clear set from memory
        delete sets[ '_' + inx ];
}


//////////////////////////////////////////////


curInx: 8


curInx: 9


curInx: 10


curInx: 11

deleting inx: 1  i: 0   obj: 1_a
deleting inx: 1  i: 1   obj: 1_b
deleting inx: 1  i: 2   obj: 1_c
deleting inx: 1  i: 3   obj: 1_d
deleting inx: 1  i: 4   obj: 1_e

curInx: 12

deleting inx: 2  i: 0   obj: 2_a
deleting inx: 2  i: 1   obj: 2_b
deleting inx: 2  i: 2   obj: 2_c
deleting inx: 2  i: 3   obj: 2_d
deleting inx: 2  i: 4   obj: 2_e

curInx: 13

deleting inx: 3  i: 0   obj: 3_a
deleting inx: 3  i: 1   obj: 3_b
deleting inx: 3  i: 2   obj: 3_c
deleting inx: 3  i: 3   obj: 3_d
deleting inx: 3  i: 4   obj: 3_e



_____________________________

Jesse Graupmann
www.jessegraupmann.com 
www.justgooddesign.com/blog/ 
_____________________________




-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Erich
Erlangga
Sent: Wednesday, April 25, 2007 6:15 PM
To: [email protected]
Subject: RE: [Flashcoders] WhITE SNOW and Seven Dwarf - MAth Problems!

onEnterFrame/setInterval function is just to give spreading effect to the
app. 
  as I mention earlier, using for loop doesnt't let any animation play
before loop ends. 
  the real problem is only about the SEQUENCE-PATTERN. 
  but, to make my question clearer 
  1. for example: there are 7000 nodes to count
  2. using one variable such as i inside loop is OK, although using for loop
to counts 
      more  than 2000 nodes make everything slows down
   
      for (var i=0;  i<7000; i++) drawNodes();--> hangs!!
             
      but I want the counting process run faster by adding another variable
which counts
      with different starting Number. thats is DIVIDING the drawing process
into 7 part and
      run simultaneously as well
   
  3. explaining my previous code:
     variable a counts ---> 1,  8,  15,  22 and so forth......adding 7 to
prev number each time
     variable a counts ---> 2,  9,  16,  23 and so forth......adding 7 to
prev number each time
     variable c counts ---> 3, 10,  17, 24 and so forth......adding 7 to
prev number each time
     variable d counts ---> 4, 11,  18, 25 and so forth......adding 7 to
prev number each time
     variable e counts ---> 5, 12,  19, 26 and so forth......adding 7 to
prev number each time
     variable f counts --->  6, 13,  20, 27 and so forth......adding 7 to
prev number each time
     variable g counts ---> 7, 14,  21, 28 and so forth......adding 7 to
prev number each time
    
     it is very much like telling 7 people to count 1000 number at different
start and at the
    same time. As a result,  the total 7000 nodes are ALL being read with
shorter time. 
     if only one such as variable "i" in many normal loop, then variable "i"
would count one, 
     two,  three ........ up to...seven thousand (and a hospital await in
front of "i")
     
     i guess there must be a math/words for this sequence and to achieve 
     the result in a smarter way
  

Danny Kodicek <[EMAIL PROTECTED]> wrote:
  

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Erich Erlangga
> Sent: 24 April 2007 14:27
> To: [email protected]
> Subject: [Flashcoders] WhITE SNOW and Seven Dwarf - MAth Problems!


> //run 7 times faster for attaching symbol in the library
> //(depends on how many people count)
> var a = 1;
> var b = 2;
> var c = 3;
> var d = 4;
> var e = 5;
> var f = 6;
> var g = 7;
> trace("first Number = " + a + " - " + b + " - " + c + " - " + 
> d + " - " + e + " - " + f + " - " + g);
> trace("Next Number =" + newline);
> _root.onEnterFrame = function(){
> 
> a +=7;
> b +=7;
> c +=7;
> d +=7;
> e +=7;
> f +=7;
> g +=7;
> 
> trace(a + " - " + b + " - " + c + " - " + d + " - " + e + " 
> - " + f + " - " + g);
> if (g == 70){
> delete _root.onEnterFrame ;
> }
> 
> }

Yes, that does look a bit odd. How about something like:

var tIndex = 1
_root.onEnterFrame = function() {
for (var i=0; i<7 i++) {
trace(tIndex++) 
}
if (tIndex == 70) { 
delete _root.onEnterFrame 
}
};

Danny

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com




       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to