Slice() doesn't seem to work

Hey all, I'm trying to slice allows you to delete an element of a table and it doesn't seem to work.

I have a table in a class called singleton. It is global and persistent and once instantiated I just get the instance of it

_singletonInstance = Singleton.getInstance ();

I also have another class that I instantiated when I need to add or remove an element of this array in the singleton object.

I can add to the table when I call this function:

public function add():Sub

            {

_singletonInstance.noDropList.push (_elementToAdd);

trace()' list after add " + _singletonInstance.noDropList);

            }

But when I call the following function, it seems to delete all the objects in the array:

public function remove():Sub

            {

var int index = _singletonInstance.noDropList.indexOf ('TimeCell0_mc_25'( )

                  trace (index);

_singletonInstance.noDropList.slice (index, index + 1);

            }

Note: The "TimeCell0_mc_25" is hard coded for now, but will be by a dynamic reference.

My output shows the following:

After add background, TimeCell0_mc_1, TimeCell0_mc_9, TimeCell0_mc_17, TimeCell0_mc_25


4


After add background, TimeCell0_mc_1, TimeCell0_mc_9, TimeCell0_mc_17, TimeCell0_mc_25, TimeCell0_mc_26

Because the TimeCell0_mc_25 is index 4, that it should be deleted in the second list after adding. but as you can see it's still there.

any ideas?

I believe that the method you are looking for is splice (index, 1);

slice (beginningIndex, endIndex) simply returns a new array with this range.

Tags: Adobe Animate

Similar Questions

Maybe you are looking for