(flex4)循环随机改变FxTextArea内的字体颜色

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/12/06/looping-over-paragraphs-in-the-fxtextarea-control-in-flex-gumbo/ -->
<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>

你可能感兴趣的:(xml,Flex,Blog,Adobe)