A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: odd array issue

  1. #1
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194

    odd array issue

    Hi,

    I'm trying to use this line to delete an element in my array

    ScrollObjectsList.slice(Number(CurrentSelected),1) ;

    but it doesn't seem to be deleting the actual data somehow, but when I use

    ScrollObjectsList[Number(CurrentSelected)] = 0;

    it works fine, any ideas??

    boombanguk

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    to delete an element use array.splice

    myArray.splice(2,1);
    ^---removes the element at index 2 in myArray

    slice extracts a substring of the array and returns it as a new array

  3. #3
    Senile member! :)
    Join Date
    Dec 2001
    Location
    Saunaswamp (transl)
    Posts
    2,296
    I think it's splice() you should use. Slice only creates a new array consisting of the "copies" of the specified elements.

    /Mirandir

  4. #4
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    sorry my bad, I was actually using splice not slice. But it wasn't working. Basically the array is a list of objects that create movie clips on screen. When I debug it, splice seems to delete the value from the array, but once the code is ran to create the clips from the array the clip object that should of been deleted (and that I saw get deleted in debug) reappears!, the only explanation is that it wasn't deleted somehow, but like i said, when I do = 0 it works fine, and the deleted clip doesn't reappear....weird. Wondering if its got something to do with the order being shifted??

  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    have you tried declaring the variable outside of the splice -

    id = Number(CurrentSelected);
    trace(id+" - "+typeof id);
    ScrollObjectsList.splice(id,1) ;

  6. #6
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    just tried that, doens't work.

    is there any way, that the data inside the element that i'm trying to splice is being shifted somehow into the next/previous element?

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    being shifted somehow into the next/previous element?

    Only if you are telling it to.
    Suggest you use trace to figure the logic ..ie -

    Code:
    ScrollObjectsList=["a","b","c","d"];
    
    CurrentSelected = "1";
    id = Number(CurrentSelected);
    trace(id+" - "+typeof id); // 1 - number
    
    trace(ScrollObjectsList); // a,b,c,d
    
    ScrollObjectsList.splice(id,1) ;
    
    trace(ScrollObjectsList); // a,c,d

  8. #8
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    ok im doing that now, but something I just realised was, I'm actually using arrays in arrays, i.e each element contains another array (and the content of the arrays are instances of classes), could that be messing with it somehow?

  9. #9
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    ah, i'm wondering if its got something to do with the fact that the arrays are arrays of instances of classes (which contain arrays of more instances to classes) could it be because they are objects, they are not being destroyed, even though their place in the array is??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center