Flex Gumbo中如何利用export()以及E4X遍历FxTextArea内的段落的例子
By Minidxer | June 1, 2009
接下来的例子演示了Flex Gumbo中如何利用export()以及E4X,遍历FxTextArea内的段落。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <Application name="FxTextArea_export_test"
- xmlns="http://ns.adobe.com/mxml/2009"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <Script>
- private function getParagraphs():void {
- var textFlowNS:Namespace = new Namespace("http://ns.adobe.com/textLayout/2008");
- var xml:XML = textArea.export();
- var xmlList:XMLList = xml.textFlowNS::p;
- var para:XML;
- for each (para in xmlList) {
- para.@color = getRandomColor();
- }
- textArea.content = xml;
- }
- private function getRandomColor():String {
- return "0x" + Math.round(Math.random() * 0xFFFFFF).toString(16);
- }
- </Script>
- <ApplicationControlBar dock="true">
- <FxButton label="Randomize paragraph colors"
- click="getParagraphs();" />
- </ApplicationControlBar>
- <FxTextArea id="textArea" width="240" height="160">
- <content>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- <p>The quick brown fox jumped over the lazy dog.</p>
- </content>
- </FxTextArea>
- </Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
FxTextArea, Gumbo |
No Comments » |
Tags: content, export(), FxTextArea, Gumbo, TextFlow