Search code examples
actionscript-3haxecode-translation

AS3 delete dictionary[key] in Haxe


I have come across this when using as3hx to port my AS3 code to Haxe:

delete classMemberDictionary[key]

as3hx can't translate this to Haxe, you have to do it manually. I've read the as3hx README and it says

  1. if it is a local variable, replace delete varname with varname = null
  2. if it is a class member variable, remove the delete entirely

Since it is a dictionary item it doesn't seem right to just remove the line, as the README says. Should I set it to null?


Solution

  • Are you using Map or openfl.utils.Dictionary? In either case you can use remove():

    Setting the value to null isn't quite the same. Although get() would return null in either case, exists() still returns true for entries that weren't explicitly removed.