Removing elements from a Dictionary

Is there a “right” way of removing an element from a Dictionary?

In AS3, I would use the delete statement:

delete myDict[keyName];

In openfl, the Dictionary class doesn’t seem to have any sort of mechanism to remove an entry. Right now what I’m doing is, I assign null to a key. Unfortunately, this still means the entry “exists” and it comes up in for loops.

Is there a better way to do this?

It’s probably better to use Map instead.

so what I ask is impossible?


-> :wink:

…if myMap is not a Dictionary. Which it is, because I’m converting a lot of code from as3 with a script.

But I get it, thank you for the answer.

I’ve just checked the source. Dictionary is a map. So you could do myDict.remove(keyName);

I tried that, it does not work. The compiler says Dictionary has no such method.

You can override the Dictionary class if you like. Put an openfl folder in your source directory, put a utils folder inside that, and make a class named Dictionary.hx. Then add this:

package openfl.utils;

typedef Dictionary = Map<String, Dynamic>;

Hey everybody,

I’ve just added dictionary.remove to OpenFL, will go out soon (today if things go well)

It calls delete on Flash Player, does a standard remove elsewhere


Thank you for making the Dictionary class usable! Very much appreciated.