Label의 추가되는 글자의 길이가 Label컴포넌트의 길이를 벗어나려하면 지우고 다시 쓰는 예제입니다. Label컴포넌트의 measureText속성이 KeyPoint입니다.



<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                       xmlns:s="library://ns.adobe.com/flex/spark"

                       xmlns:mx="library://ns.adobe.com/flex/mx">

 

       <fx:Script>

             <![CDATA[

                    import flash.utils.setTimeout;

 

                    import mx.events.FlexEvent;

 

                    private var i:Number=0;

                    private var testTimer:Timer;

 

                    private function onClick():void

                    {

                           testTimer=new Timer(100, 1000);

                           testTimer.addEventListener(TimerEvent.TIMER, timerHandler);

                           testTimer.start();

                    }

 

                    public function timerHandler(event:TimerEvent):void

                    {

                           if (lbl.measureText(lbl.text).width > lbl.width - 20)

                                 lbl.text="";

 

                           lbl.text+=i.toString();

                           i++;

                    }

             ]]>

       </fx:Script>

 

       <s:VGroup>

             <mx:Button click="onClick()"/>

             <s:Label id="lbl"

                            backgroundColor="#FF0000"

                            width="100"/>

       </s:VGroup>

</s:Application>


measureText Reference

저작자 표시 비영리 변경 금지
신고
YOUR COMMENT IS THE CRITICAL SUCCESS FACTOR FOR THE QUALITY OF BLOG POST


티스토리 툴바