flash on 2011-9-11
♥0 |
Line 39 |
Modified 2011-09-11 13:49:48 |
MIT License
archived:2017-03-20 03:03:36
ActionScript3 source code
/**
* Copyright fujiopera ( http://wonderfl.net/user/fujiopera )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/t5Bb
*/
package {
import flash.display.Sprite;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.SpanElement;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.TextLayoutFormat;
public class TextLayoutFormat_concatInheritOnlyExample extends Sprite
{
public function TextLayoutFormat_concatInheritOnlyExample()
{
// create a container and add it to the stage
var container:Sprite = new Sprite();
this.stage.addChild(container);
// create TextFlow, ParagraphElement, and SpanElement objects
var textFlow:TextFlow = new TextFlow();
var p:ParagraphElement = new ParagraphElement();
var span:SpanElement = new SpanElement();
// create two TextLayoutFormat objects
var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
var textLayoutFormat2:TextLayoutFormat = new TextLayoutFormat();
// set format attributes in the first one
textLayoutFormat.color = 0xFF0000;
textLayoutFormat.fontSize = undefined;
// set attributes on the second one (fontSize set here, too)
textLayoutFormat2.color = 0x00FF00;
textLayoutFormat2.backgroundColor = 0x00CCCC;
textLayoutFormat2.fontSize = 16;
textLayoutFormat2.fontFamily = "Times Roman";
// concat textLayoutFormat2 settings; assign format to the text flow
textLayoutFormat.concatInheritOnly(textLayoutFormat2);
textFlow.hostFormat = textLayoutFormat;
// add text to the span, the span to the paragraph, and the paragraph to the text flow.
span.text = "Notice that the value of backgroundColor is "
span.text += textLayoutFormat.backgroundColor;
span.text += ", even though it is set in textLayoutFormat2. This is because " +
"this property does not inherit. Also notice that font color does not change " +
"because it is not undefined."
p.addChild( span);
textFlow.addChild(p);
// update controller to display it
var controller:ContainerController = new ContainerController(container, 200, 200 );
textFlow.flowComposer.addController(controller);
textFlow.flowComposer.updateAllControllers();
}
}
}