Re: [Flashcoders] Remove elements from Array
he told me was that FLEX could not consume web services without Flex Data Services Uh, no. You can consume webservices in Flex. I'm guessing it must conform to SOAP, which shouldn't be a problem. .NET, CF, all good. Is this true, or can FLEX consume a web serivce but with limiations? By limitations, for example, not being able to consume a .Net dataset directly - needing to pass the data into an array. Not sure what you mean by that. You can hook up to a webservice. You cannot hook up 'directly' to .NET, if you mean some kind of remoting connection (RTMP?), unless you set something up like that in .NET. PHP has AMFPHP and CF has Flash Remoting built in. However, you could set up a socket server in .NET and hook flex 2 directly to that, since it now has binary socket functionality. -Scott On 12/22/06, Brake, Stephen <[EMAIL PROTECTED]> wrote: I have a Flex question. I have been considering FLEX 2.0, but when I spoke with the guy at Adobe, the first thing he told me was that FLEX could not consume web services without Flex Data Services and the price he quoted me for the Departmental License was (well, lets not say). Is this true, or can FLEX consume a web serivce but with limiations? By limitations, for example, not being able to consume a .Net dataset directly - needing to pass the data into an array. Thanks, Steve From: [EMAIL PROTECTED] on behalf of Mike Cobb Sent: Thu 12/21/2006 11:58 AM To: Flashcoders mailing list Subject: [Flashcoders] Remove elements from Array - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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 -- : : ) Scott ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
The Array.splice method, in AS1 at least, is very slow. For that reason, In situations like this where you would make repeated calls to it to remove one item I prefer to: - create a new Array - iterate the original array with a for loop - push the items I want to keep into the new array - dispose the old one when done. On Dec 22, 2006, at 12:09 AM, Arindam Dhar wrote: Try this, var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); trace( myArray1); // the function with recursion function removeElements(arr, level) { for (var i = 0; i wrote: - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 Send instant messages to your online friends http:// asia.messenger.yahoo.com ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
RE: [Flashcoders] Remove elements from Array
Thanks for the comments and, trust me there is no epeen involved :-) Steven Sacks | BLITZ <[EMAIL PROTECTED]> wrote: That's a fantastic example of over-architecting if I ever saw one. Put away your epeen! ;) > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf > Of Arindam Dhar > Sent: Friday, December 22, 2006 12:10 AM > To: Flashcoders mailing list > Subject: Re: [Flashcoders] Remove elements from Array > > function removeElements(arr, level) { > > for (var i = 0; i> { > var tempArr = arr[i]; > > if(Number(tempArr[1] ) < Number(level)) > { > arr.splice(i, 1); > arguments.callee(arr, level); > } > > } > } > removeElements(myArray1, 0); > trace( myArray1); > > Arindam ___ Flashcoders@chattyfig.figleaf.com 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 Send instant messages to your online friends http://asia.messenger.yahoo.com ___ Flashcoders@chattyfig.figleaf.com 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
RE: [Flashcoders] Remove elements from Array
I have a Flex question. I have been considering FLEX 2.0, but when I spoke with the guy at Adobe, the first thing he told me was that FLEX could not consume web services without Flex Data Services and the price he quoted me for the Departmental License was (well, lets not say). Is this true, or can FLEX consume a web serivce but with limiations? By limitations, for example, not being able to consume a .Net dataset directly - needing to pass the data into an array. Thanks, Steve From: [EMAIL PROTECTED] on behalf of Mike Cobb Sent: Thu 12/21/2006 11:58 AM To: Flashcoders mailing list Subject: [Flashcoders] Remove elements from Array - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
RE: [Flashcoders] Remove elements from Array
That's a fantastic example of over-architecting if I ever saw one. Put away your epeen! ;) > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf > Of Arindam Dhar > Sent: Friday, December 22, 2006 12:10 AM > To: Flashcoders mailing list > Subject: Re: [Flashcoders] Remove elements from Array > > function removeElements(arr, level) { > > for (var i = 0; i { > var tempArr = arr[i]; > >if(Number(tempArr[1] ) < Number(level)) >{ > arr.splice(i, 1); > arguments.callee(arr, level); >} > > } > } > removeElements(myArray1, 0); > trace( myArray1); > > Arindam ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
Try this, var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); trace( myArray1); // the function with recursion function removeElements(arr, level) { for (var i = 0; i wrote: - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 Send instant messages to your online friends http://asia.messenger.yahoo.com ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
Well now I just feel dumb. That's much better than my while loop, and simple enough I should have thought of it (I've even done something like that before). Doh! -Andy On 12/21/06, Jim Kremens <[EMAIL PROTECTED]> wrote: "for (var i:Number = array.length - 1; i >= 0; --i) { if (!test(array[i])) { array.splice(i, 1); } }" This is correct and well tested... Look in any of the AS code libraries and you'll find many variations on this theme. Jim Kremens On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote: > Well, easy enough, then: > > for (var i:Number = array.length - 1; i >= 0; --i) { >if (!test(array[i])) { >array.splice(i, 1); >} > } > > On 12/21/06, Andy Herrman <[EMAIL PROTECTED]> wrote: > > Even if it iterates backwards, I don't think I'd trust it. I don't > > like the idea of relying on an implementation detail of the for-in > > loop in order to make my stuff work. In general I see for-in loops > > (any language) as loops that use an arbitrary ordering, and as such > > you shouldn't rely on any particular ordering for your code to work. > > I tend to think it's safer to approach things this way, as it protects > > you from any changes in the implementation details. Just the fact > > that you're "Not sure about AS3" is reason enough I think. > > > > But maybe I'm just paranoid. :) > > > >-Andy > ___ > Flashcoders@chattyfig.figleaf.com > 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 > -- Jim Kremens ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
"for (var i:Number = array.length - 1; i >= 0; --i) { if (!test(array[i])) { array.splice(i, 1); } }" This is correct and well tested... Look in any of the AS code libraries and you'll find many variations on this theme. Jim Kremens On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote: Well, easy enough, then: for (var i:Number = array.length - 1; i >= 0; --i) { if (!test(array[i])) { array.splice(i, 1); } } On 12/21/06, Andy Herrman <[EMAIL PROTECTED]> wrote: > Even if it iterates backwards, I don't think I'd trust it. I don't > like the idea of relying on an implementation detail of the for-in > loop in order to make my stuff work. In general I see for-in loops > (any language) as loops that use an arbitrary ordering, and as such > you shouldn't rely on any particular ordering for your code to work. > I tend to think it's safer to approach things this way, as it protects > you from any changes in the implementation details. Just the fact > that you're "Not sure about AS3" is reason enough I think. > > But maybe I'm just paranoid. :) > >-Andy ___ Flashcoders@chattyfig.figleaf.com 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 -- Jim Kremens ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
Well, easy enough, then: for (var i:Number = array.length - 1; i >= 0; --i) { if (!test(array[i])) { array.splice(i, 1); } } On 12/21/06, Andy Herrman <[EMAIL PROTECTED]> wrote: Even if it iterates backwards, I don't think I'd trust it. I don't like the idea of relying on an implementation detail of the for-in loop in order to make my stuff work. In general I see for-in loops (any language) as loops that use an arbitrary ordering, and as such you shouldn't rely on any particular ordering for your code to work. I tend to think it's safer to approach things this way, as it protects you from any changes in the implementation details. Just the fact that you're "Not sure about AS3" is reason enough I think. But maybe I'm just paranoid. :) -Andy ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
Even if it iterates backwards, I don't think I'd trust it. I don't like the idea of relying on an implementation detail of the for-in loop in order to make my stuff work. In general I see for-in loops (any language) as loops that use an arbitrary ordering, and as such you shouldn't rely on any particular ordering for your code to work. I tend to think it's safer to approach things this way, as it protects you from any changes in the implementation details. Just the fact that you're "Not sure about AS3" is reason enough I think. But maybe I'm just paranoid. :) -Andy On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote: No, because it's a for (x in a) loop, not a for (x; y; z) loop. In AS2 it iterates backwards over the elements. Not sure about AS3, but it should work there, too. Try it and see! On 12/21/06, Andy Herrman <[EMAIL PROTECTED]> wrote: > Wouldn't doing the splice there change the indexes of everything else > in the array and mess up the loop? > > For instance: > > [1, 2, A, A, 5, A, 7] > > say you're deleting the As. > > The first time you do a splice you remove the first one, and get: > > [1, 2, A, 5, A, 7] > > The index of everything after the first A has now changed. The second > one is now at index 3, but you already handled index 3 in the for > loop. Is the for-in loop smart enough to run index 3 again, since the > value there is new? ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
No, because it's a for (x in a) loop, not a for (x; y; z) loop. In AS2 it iterates backwards over the elements. Not sure about AS3, but it should work there, too. Try it and see! On 12/21/06, Andy Herrman <[EMAIL PROTECTED]> wrote: Wouldn't doing the splice there change the indexes of everything else in the array and mess up the loop? For instance: [1, 2, A, A, 5, A, 7] say you're deleting the As. The first time you do a splice you remove the first one, and get: [1, 2, A, 5, A, 7] The index of everything after the first A has now changed. The second one is now at index 3, but you already handled index 3 in the for loop. Is the for-in loop smart enough to run index 3 again, since the value there is new? ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
Wouldn't doing the splice there change the indexes of everything else in the array and mess up the loop? For instance: [1, 2, A, A, 5, A, 7] say you're deleting the As. The first time you do a splice you remove the first one, and get: [1, 2, A, 5, A, 7] The index of everything after the first A has now changed. The second one is now at index 3, but you already handled index 3 in the for loop. Is the for-in loop smart enough to run index 3 again, since the value there is new? -Andy On 12/21/06, T. Michael Keesey <[EMAIL PROTECTED]> wrote: Quite simple: for (var key:String in myArray1) { if (myArray1[key][1] < 0) { myArray1.splice(Number(key), 1); } } BTW, "myArray1" is not a great name for a variable ... why not "scoreRecords" or "scores" or something? Also, storing different types of data in an array is a recipe for confusions. The element arrays would be better as objects, e.g.: {name: "A", score: -1}.Then the code would be more readable: for (var key:String in scoreRecords) { var record:Object = scoreRecords[key]; if (record.score < 0) { scoreRecords.splice(Number(key), 1); } } Or the whole thing could just be an associative array (i.e., hash object): var scores:Object = {A: -1, B: -1, C: 0}; // ... for (var key:String in scoreRecords) { if (scoreRecords[key] < 0) { delete scoreRecords[key]; } } On 12/21/06, Mike Cobb <[EMAIL PROTECTED]> wrote: > - > > Hi everyone, > > I'm having a braindead moment today, which I was hoping someone could > help me with. > > I have the following array... > > //Create array with 5 elements > var myArray1:Array = new Array(); > myArray1.push( new Array("A:", -1) ); > myArray1.push( new Array("B:", -1) ); > myArray1.push( new Array("C:", 0) ); > myArray1.push( new Array("D:", 0) ); > myArray1.push( new Array("E:", -1) ); > myArray1.push( new Array("F:", 1) ); > myArray1.push( new Array("G:", 0) ); > myArray1.push( new Array("H:", -1) ); > //name, score > > ...and I'm trying to remove all the elements in myArray1 with a score of > less than 0 without sorting/reordering the array at all. > > I was trying to use a 'for loop', but obviously as the elements are > removed, the length of the array changes & causes the wrong elements to > be deleted. > > Can anyone help? > > Thanks, > > > -- > - > Mike Cobb > Creative Director > HMC Interactive > - > Tel: + 44 (0)845 20 11 462 > Mob: + 44 (0)785 52 54 743 > Web: http://www.hmcinteractive.co.uk > - > Grosvenor House, Belgrave Lane, > Plymouth, PL4 7DA, UK. > - > > I've got a new e-mail address: [EMAIL PROTECTED] > Please update your address book. Thanks. > > ___ > Flashcoders@chattyfig.figleaf.com > 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 > -- T. Michael Keesey Director of Technology Exopolis, Inc. 2894 Rowena Avenue Ste. B Los Angeles, California 90039 -- The Dinosauricon: http://dino.lm.com Parry & Carney: http://parryandcarney.com ISPN Forum: http://www.phylonames.org/forum/ ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
- Thanks Michael - that's an elegant solution. Don't worry about the array name though - just a simplified example for the sake of the list. Thanks again all. T. Michael Keesey wrote: Quite simple: for (var key:String in myArray1) { if (myArray1[key][1] < 0) { myArray1.splice(Number(key), 1); } } BTW, "myArray1" is not a great name for a variable ... why not "scoreRecords" or "scores" or something? Also, storing different types of data in an array is a recipe for confusions. The element arrays would be better as objects, e.g.: {name: "A", score: -1}.Then the code would be more readable: for (var key:String in scoreRecords) { var record:Object = scoreRecords[key]; if (record.score < 0) { scoreRecords.splice(Number(key), 1); } } Or the whole thing could just be an associative array (i.e., hash object): var scores:Object = {A: -1, B: -1, C: 0}; // ... for (var key:String in scoreRecords) { if (scoreRecords[key] < 0) { delete scoreRecords[key]; } } On 12/21/06, Mike Cobb <[EMAIL PROTECTED]> wrote: - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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
RE: [Flashcoders] Remove elements from Array
//Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); var i:Number = 0; while(myArray1[i]){ if(myArray1[i][1] < 0){ myArray1.splice(i, 1); }else{ i++; }; }; delete i; // ^_^ - - - - - - - - - -[andrew murphy]- flash developer [EMAIL PROTECTED] delvinia interactive inc. 214 king street west, suite 214 toronto canada M5H 3S6 voice 416.364.1455 ext. 232 cell 416.820.8723 fax 416.364.9830 www.delvinia.com CONFIDENTIALITY NOTICE This email message may contain privileged or confidential information. If you are not the intended recipient or received this communication by error, please notify the sender and delete the message without copying or disclosing it. AVIS DE CONFIDENTIALITÉ Ce message peut contenir de l'information légalement privilégiée ou confidentielle. Si vous n'êtes pas le destinataire ou croyez avoir reçu par erreur ce message, nous vous saurions gré d'en aviser l'émetteur et d'en détruire le contenu sans le communiquer a d'autres ou le reproduire. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mike Cobb Sent: December 21, 2006 11:58 AM To: Flashcoders mailing list Subject: [Flashcoders] Remove elements from Array - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 -- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.15.26/594 - Release Date: 20/12/2006 3:54 PM -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.15.26/594 - Release Date: 20/12/2006 3:54 PM ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
- oh brilliant - just what I needed. Thanks Andy! Andy Herrman wrote: you could use a while loop: var i:Number = 0 while(i < myArray1.length) { if(myArray1[i][1] == 0) { /* I think this is right: */ myArray1.splice(i, 1); } else { i++; } } Splicing will cause the next item to be at index i, so you want to recheck that index the next time through the loop. Or you could loop over it and just store another array containing the indexes of the ones you need to remove, then loop through that and remove from the array (go backwards though, so that the indexes of unremoved ones won't be changed by removing others). -Andy On 12/21/06, Mike Cobb <[EMAIL PROTECTED]> wrote: - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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 -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
Quite simple: for (var key:String in myArray1) { if (myArray1[key][1] < 0) { myArray1.splice(Number(key), 1); } } BTW, "myArray1" is not a great name for a variable ... why not "scoreRecords" or "scores" or something? Also, storing different types of data in an array is a recipe for confusions. The element arrays would be better as objects, e.g.: {name: "A", score: -1}.Then the code would be more readable: for (var key:String in scoreRecords) { var record:Object = scoreRecords[key]; if (record.score < 0) { scoreRecords.splice(Number(key), 1); } } Or the whole thing could just be an associative array (i.e., hash object): var scores:Object = {A: -1, B: -1, C: 0}; // ... for (var key:String in scoreRecords) { if (scoreRecords[key] < 0) { delete scoreRecords[key]; } } On 12/21/06, Mike Cobb <[EMAIL PROTECTED]> wrote: - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 -- T. Michael Keesey Director of Technology Exopolis, Inc. 2894 Rowena Avenue Ste. B Los Angeles, California 90039 -- The Dinosauricon: http://dino.lm.com Parry & Carney: http://parryandcarney.com ISPN Forum: http://www.phylonames.org/forum/ ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
That's probably more efficient than my method. Granted, I may be wrong about how Flash stores arrays internally, but in general removing a single element from an array requires everything after that element to be shifted left. So the closer to the beginning of the array the more expensive the removal will be (as everything after it has to be moved). If you're removing multiple things it could very easily become more efficient to just make a new array. You could write a loop that does this with the least number of moves, but it can get a bit complicated (I've done it, it was fun). -Andy On 12/21/06, slangeberg <[EMAIL PROTECTED]> wrote: What if you create a new array and push the good values ( < 0 ) onto it, then replace the old array with the new, at the end of the loop? Simple. Efficient? Probably, unless your array gets huge. -Scott On 12/21/06, Mike Cobb <[EMAIL PROTECTED]> wrote: > > - > > Hi everyone, > > I'm having a braindead moment today, which I was hoping someone could > help me with. > > I have the following array... > > //Create array with 5 elements > var myArray1:Array = new Array(); > myArray1.push( new Array("A:", -1) ); > myArray1.push( new Array("B:", -1) ); > myArray1.push( new Array("C:", 0) ); > myArray1.push( new Array("D:", 0) ); > myArray1.push( new Array("E:", -1) ); > myArray1.push( new Array("F:", 1) ); > myArray1.push( new Array("G:", 0) ); > myArray1.push( new Array("H:", -1) ); > //name, score > > ...and I'm trying to remove all the elements in myArray1 with a score of > less than 0 without sorting/reordering the array at all. > > I was trying to use a 'for loop', but obviously as the elements are > removed, the length of the array changes & causes the wrong elements to > be deleted. > > Can anyone help? > > Thanks, > > > -- > - > Mike Cobb > Creative Director > HMC Interactive > - > Tel: + 44 (0)845 20 11 462 > Mob: + 44 (0)785 52 54 743 > Web: http://www.hmcinteractive.co.uk > - > Grosvenor House, Belgrave Lane, > Plymouth, PL4 7DA, UK. > - > > I've got a new e-mail address: [EMAIL PROTECTED] > Please update your address book. Thanks. > > ___ > Flashcoders@chattyfig.figleaf.com > 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 > -- : : ) Scott ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
you could use a while loop: var i:Number = 0 while(i < myArray1.length) { if(myArray1[i][1] == 0) { /* I think this is right: */ myArray1.splice(i, 1); } else { i++; } } Splicing will cause the next item to be at index i, so you want to recheck that index the next time through the loop. Or you could loop over it and just store another array containing the indexes of the ones you need to remove, then loop through that and remove from the array (go backwards though, so that the indexes of unremoved ones won't be changed by removing others). -Andy On 12/21/06, Mike Cobb <[EMAIL PROTECTED]> wrote: - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] Remove elements from Array
What if you create a new array and push the good values ( < 0 ) onto it, then replace the old array with the new, at the end of the loop? Simple. Efficient? Probably, unless your array gets huge. -Scott On 12/21/06, Mike Cobb <[EMAIL PROTECTED]> wrote: - Hi everyone, I'm having a braindead moment today, which I was hoping someone could help me with. I have the following array... //Create array with 5 elements var myArray1:Array = new Array(); myArray1.push( new Array("A:", -1) ); myArray1.push( new Array("B:", -1) ); myArray1.push( new Array("C:", 0) ); myArray1.push( new Array("D:", 0) ); myArray1.push( new Array("E:", -1) ); myArray1.push( new Array("F:", 1) ); myArray1.push( new Array("G:", 0) ); myArray1.push( new Array("H:", -1) ); //name, score ...and I'm trying to remove all the elements in myArray1 with a score of less than 0 without sorting/reordering the array at all. I was trying to use a 'for loop', but obviously as the elements are removed, the length of the array changes & causes the wrong elements to be deleted. Can anyone help? Thanks, -- - Mike Cobb Creative Director HMC Interactive - Tel: + 44 (0)845 20 11 462 Mob: + 44 (0)785 52 54 743 Web: http://www.hmcinteractive.co.uk - Grosvenor House, Belgrave Lane, Plymouth, PL4 7DA, UK. - I've got a new e-mail address: [EMAIL PROTECTED] Please update your address book. Thanks. ___ Flashcoders@chattyfig.figleaf.com 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 -- : : ) Scott ___ Flashcoders@chattyfig.figleaf.com 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