Hey guys, I got stuck on Textflow copy-paste operation, I want to copy plain text from a textflow, don't want any text format/style but InlineGraphics, how can I do this?
I'm follow this Example http://blogs.adobe.com/tlf/2010/11/custom-clipboard-formats.html , create a PlainTextExporter extends ConverterBase and implements ITextImporter, and
TextConverter.addFormatAt(0, "plainText", PlainTextImporter);
But the PlainTextImporter never instantiation. nothing happened
create a PlainTextExporter extends ConverterBase and implements ITextImporter, and
TextConverter.addFormatAt(0, "plainText", PlainTextImporter);
1. Did you create PlainTextExporter but register PlainTextImporter? I believe it must be a typo. ![]()
2. What's more, the fifth paramter of addFormatAt should not be null when you take advantage of Custom Clipboard.
/**
* Register a new format for import/export, at the specified location.
* Location can be significant for clients that have multiple
* choices for which format to use, such as when importing from the external clipboard.
* Lower numbers indicate higher priority; these converters will be tried first.
* The new format may support importing and/or exporting.
* If the format has already been added, then it will be present in multiple locations. The
* first one found will be used.
*
* @playerversion Flash 10
* @playerversion AIR 1.5
* @langversion 3.0
* @param importClass The import converter class to register or null
* @param exportClass The export converter class to register or null
* @param format The format string tagging the converter classes
* @param clipboardFormat The string used as the clipboard format when converting to/from the clipboard. Make this null if the format doesn't support clipboard access.
*/
public static function addFormatAt(index:int, format:String, importerClass:Class, exporterClass:Class = null, clipboardFormat:String = null):void
3. The example in blog only includes a importer. There can also be a exporter. Importer is called when you copy, while exporter when you paste.
4. You must pay attention to the *if-condition* in importToFlow() of importer.
yes, I have create a
public class PlainTextImporter extends ConverterBase implements ITextImporter
{
protected var _config:IConfiguration = null;
public function PlainTextImporter()
{
super();
trace("PlainTextImporter inited.");
}
public function importToFlow(source:Object):TextFlow
{
trace("import", source);
if(source is String)
{
var importer:ITextImporter =
TextConverter.getImporter(TextConverter.PLAIN_TEXT_FORMAT);
return importer.importToFlow(source);
}
return null;
}
public function get configuration():IConfiguration
{
return _config;
}
public function set configuration(value:IConfiguration):void
{
_config = value;
}
}
and register it after interactionManager's instantiation (I found a PlainTextExporter at flashx.textLayout.conversion package)
messageFlow.interactionManager = new SelectionManager();
TextConverter.addFormatAt(0, "plainText", PlainTextImporter, PlainTextExporter);
messageFlow is a TextFlow instance, but when I copy text from it , the traces
trace("PlainTextImporter inited.");
and
trace("import", source);
in PlainTextImporter class never go through.
Did I call the TextConverter.addFormatAt() method in the wrong place?
Is TextConverter influences the global copy behaviours in all TextFlows?
Please pay attention to the bold words of item 2 in my last reply. You cannot miss the fifth paramter.
TextConverter.addFormatAt(0, "plainText", PlainTextImporter, PlainTextExporter, "air:text");
Is TextConverter influences the global copy behaviours in all TextFlows?
Yes, but you can add if-conditions in importToFlow() to skip it under some circumstances.
I'm follow your steps, and add my PlainTextImporter to the TextConverter.
I can see a new FormatDescriptor insert to the _descriptors array, which inside the TextConverter with tlf_internal namespace.
But when I copy from the TextFlow, my PlainTextImporter still not work, never initialize or importToFlow be called.
A screenshot goes here, http://d.pr/i/eK08
One more thing, I can't upload an image from my computer, don't know why.
Maybe you can refer to the code of flashx.textLayout.conversion.TextConverter, the default importers and exporters.
The default clipboard is
static tlf_internal function setFormatsToDefault():void
{
_descriptors = [];
addFormat(TEXT_LAYOUT_FORMAT, TextLayoutImporter, TextLayoutExporter, TEXT_LAYOUT_FORMAT);
addFormat(TEXT_FIELD_HTML_FORMAT, TextFieldHtmlImporter, TextFieldHtmlExporter, null);
addFormat(PLAIN_TEXT_FORMAT, PlainTextImporter, PlainTextExporter, "air:text");
}
Besides, you may want to change the name of your class to avoid unexpected issues. You can see that there is already a TLF importer named PlainTextImporter.
North America
Europe, Middle East and Africa
Asia Pacific