dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Removing items in a Array based on label

  1. #1
    Interactive Designer
    Join Date
    May 2006
    Location
    Connecticut
    Posts
    154

    Removing items in a Array based on label

    Hello!

    I am looking for a way to remove items from an array, via label. Or find a way to get the index number of an array, by specifiying the label name, so i can dynamically remove array items.

    Thanks for the help in advance!

    Mike

  2. #2
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Removing any helpful previous posts I mistakenly contributed to these forums.

    See ya FK'ers
    Last edited by NTD; 10-19-2006 at 06:14 AM.

  3. #3
    Member
    Join Date
    Apr 2006
    Posts
    51
    Hi
    Well the truth is, that to my knowledge Flash was no function to retrieve the index number of a specific label in an array or to remove a specific label from an array.
    But that’s ok, because you create your own functions and the reuse them as with any other function.

    So let’s say I want to find out what index number the word “tree” has in the array
    objects = [“apple”,”computer”,”Cd”,”tree”,”girlfriend”]; 
    test=”tree”

    position_test = findIndex(objects,test);

    function findIndex (objects,test) {
    i=0;
    while (i<objects.length) {
    if (objects[i] == test) {indexnumber= i;}
    /*please pay attention if you happen to have two objects with the same name, indexnumer will return the last one. To counteract this you can write a after indexnumber =i; i=objects.length; , in this way the first occurrence of the specified label will be returned */
    i++;}
    return indexnumber };

    To remove the specified label just use splice(i.e. object.splice(position_test,1);

    Hope it works

    DarkSoul666

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