Use “delete” to undefine a property
if (val === undefined) delete _styles[val];
Good point, I've tried that and it works. But in this case I need to keep the undo-stack intact, and manipulating properties directly reset it. Is there any way of clearing user styles through the EditManager?
ClearFormatOnElementOperation or ClearFormatOperation
No, that doesn't work. Or at least, ClearFormatOnElementOperation doesn't work for clearing userStyles.
The below method in ClearFormatOnElementOperation does the job. The problem is that TextLayoutFormat.description object which it iterates on does not contain userStyles as far as I can see.
public override function doOperation():Boolean
var targetElement:FlowElement = getTargetElement();
_undoStyles = new TextLayoutFormat(targetElement.format);
var newFormat:TextLayoutFormat = new TextLayoutFormat(targetElement.format);
// this is fairly rare so this operation is not optimizied
for (var prop:String in TextLayoutFormat.description)
if (_format[prop] !== undefined)
newFormat[prop] = undefined;
targetElement.format = newFormat;