Package | flashx.textLayout.compose |
Interface | public interface ISWFContext |
Implementors | TextContainerManager |
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 10, AIR 1.5 |
There are two reasons for an application to use this interface to control TextLine creation:
- Reuse an embedded font: if an application wants to use a font embedded in a loaded SWF file, the application can access the font if a TextLine is created in the context of the loaded SWF file.
-
Reuse existing TextLine instances: reusing existing TextLine instances can result in faster recompose times.
TLF reuses existing TextLine instances internally. TLF reuses
a TextLine by calling
TextBlock.recreateTextLine()
instead ofTextBlock.createTextLine()
when TLF recognizes that a TextLine is extant.
Your application may have additional TextLine instances that can be reused. To manually reuse existing TextLine instances:
- trap calls to
TextBlock.createTextLine()
, then - call
TextBlock.recreateTextLine()
with the extant TextLine instance instead ofTextBlock.createTextLine()
.
Please note, however, that the TextBlock.recreateTextLine()
is available
only in Flash Player 10.1 and later.
Related API Elements
Method | Defined By | ||
---|---|---|---|
A way to call a method in a client controlled context. | ISWFContext |
callInContext | () | method |
public function callInContext(fn:Function, thisArg:Object, argArray:Array, returns:Boolean = true):*
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 10, AIR 1.5 |
A way to call a method in a client controlled context.
Parameters
fn:Function — The function or method to call
| |
thisArg:Object — The this pointer for the function
| |
argArray:Array — The arguments for the function
| |
returns:Boolean (default = true ) — If true, the function returns a value
|
* — Whatever the function returns, if anything.
|
Related API Elements
The EmbeddedFontLineCreator class implements ISWFContext and embeds a font. Other classes can load a SWF file based on EmbeddedFontLineCreator and access the embedded font.
package flashx.textLayout.compose.examples { import flash.display.Sprite; import flashx.textLayout.compose.ISWFContext; public class EmbeddedFontLineCreator extends Sprite implements ISWFContext { [Embed( source="C:\\Windows\\Fonts\\BirchStd.otf", fontFamily="embeddedBirchStd", cff="embedAsCFF", unicodeRange="U+0041-U+005A, U+0061-U+007A, U+003F")] public var embeddedBirchStdFont:Class; public function callInContext(fn:Function, thisArg:Object, argsArray:Array, returns:Boolean=true):* { if (returns) return fn.apply(thisArg, argsArray); fn.apply(thisArg, argsArray); } } }
The FontConsumer class first loads the EmbeddedFontLineCreator.swf file and waits for the
load function to succeed. Once the load succeeds, the event listener function
createFlow()
creates a text container and a text flow.
The event listener then creates a flow composer and associates the loaded SWF file
with the flow composer's swfContext
property.
This association allows a FontConsumer instance to call methods within the context of the
loaded SWF file. With access to the context of EmbeddedFontLineCreator, the FontConsumer instance
can use the font embedded in EmbeddedFontLineCreator.
package flashx.textLayout.compose.examples { import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; import flash.text.engine.FontLookup; import flashx.textLayout.compose.StandardFlowComposer; import flashx.textLayout.container.ContainerController; import flashx.textLayout.conversion.TextConverter; import flashx.textLayout.elements.Configuration; import flashx.textLayout.elements.TextFlow; import flashx.textLayout.formats.TextLayoutFormat; public class FontConsumer extends Sprite { private var fontSWF:Loader = new Loader(); public function FontConsumer() { var fontSWFURL:URLRequest = new URLRequest("EmbeddedFontLineCreator.swf"); fontSWF.contentLoaderInfo.addEventListener( Event.COMPLETE, createFlow ); fontSWF.load( fontSWFURL ); } private function createFlow( event:Event ):void { var container:Sprite = new Sprite(); this.addChild( container ); var controller:ContainerController = new ContainerController( container, 600, 700 ); var format:TextLayoutFormat = new TextLayoutFormat(); format.fontFamily = "embeddedBirchStd"; format.fontLookup = FontLookup.EMBEDDED_CFF; var config:Configuration = new Configuration(); config.textFlowInitialFormat = format; var flow:TextFlow = TextConverter.importToFlow( "Shall I compare thee to a summer's day?", TextConverter.PLAIN_TEXT_FORMAT, config ); flow.flowComposer = new StandardFlowComposer(); var embeddedFontLineCreator:Class = fontSWF.contentLoaderInfo.applicationDomain.getDefinition( "flashx.textLayout.compose.examples.EmbeddedFontLineCreator" ) as Class; flow.flowComposer.swfContext = new embeddedFontLineCreator(); flow.flowComposer.addController( controller ); flow.flowComposer.updateAllControllers(); } } }
Thu Dec 6 2018, 01:12 PM -08:00