Flex 「跑馬燈」效果(自定義「跑馬燈」控制項)

2022-03-23 19:22:24 字數 4652 閱讀 3493

自定義類(broadcastmarquee.as):

package marquee

/**初始化

*/private

function initbroadcast():void

/**

* 如果有新的廣播訊息,或者長度改變進行滾動顯示

* */private

function scrollbroadtext():void

} }

/**控制滾動資訊

*/private

function timerhandler(evt:timerevent):void

else

}else

else

} m_broadcasttext.scrollrect =m_rect;

}else

} /**停止移動

*/private

function stopmovebroadcast():void

} /**************************廣播資訊處理事件********************************

*//*

*滑鼠經過處理事件

*/protected

function rolloverhandler(event:mouseevent):void

} /**滑鼠離開處理事件

*/protected

function rollouthandler(event:mouseevent):void

} /**************************廣播資訊屬性************************************

*//*

*移動時間間隔

*/public

function set broadcastdeplay(value:number):void

/**設定廣播資訊內容

*/public

function set broadcasttext(value:string):void

/**取得廣播資訊內容

*/public

function

get broadcasttext():string

/**廣播資訊寬度寬度

*/public override

function

get width():number

public override

function set width(width:number):void

/**設定滾動方向('left' or 'right')

*/public

function set direction(value:string):void

/**設定字型格式化樣式

*/public

function set defaulttextformat(format:textformat):void

public

function settextformat(format:textformat, beginindex:int = -1, endindex:int = -1):void

/**字型大小

*/public

function set fontsize(value:object):void

/**字型名稱

*/public

function set fontfamily(value:string):void

/**字型顏色

*/public

function set color(value:object):void

/**是否是粗體

*/public

function set fontweight(value:object):void

}

}testbroadcastmarquee.mxml :

<?

xml version="1.0" encoding="utf-8"

?>

<

xmlns:mx

=""layout

="absolute"

creationcomplete

="init()"

xmlns:marquee

="marquee.*"

>

<

marquee:broadcastmarquee

width

="500"

height

="25"

broadcastdeplay

="800"

broadcasttext

="公告:火爆商品等你拿!"

scrolldirection

="left"

>

marquee:broadcastmarquee

>

>

<?

xml version="1.0" encoding="utf-8"

?>

<

xmlns:mx

=""layout

="vertical"

verticalalign

="middle"

backgroundcolor

="white"

>

<

mx:script

>

private function fade_click():void

private function wipe_click():void

]]>

mx:script

>

<

mx:sequence

id="fader"

>

<

mx:fade

alphafrom

="0.0"

alphato

="1.0"

/>

<

mx:pause

duration=""

/>

<

mx:fade

alphafrom

="1.0"

alphato

="0.0"

/>

mx:sequence

>

<

mx:sequence

id="wiper"

>

<

mx:setpropertyaction

name

="alpha"

value

="1.0"

/>

<

mx:wiperight

showtarget

="true"

/>

<

mx:pause

duration=""

/>

<

mx:wiperight

showtarget

="false"

/>

<

mx:setpropertyaction

name

="alpha"

value

="0.0"

/>

mx:sequence

>

<

dock

="true"

>

<

mx:button

label

="fade box"

click

="fade_click();"

/>

<

mx:button

label

="wipe box"

click

="wipe_click();"

/>

<

mx:spacer

width

="100%"

/>

<

mx:label

text

="effect pause ( ms):"

/>

<

mx:hslider

id="slider"

minimum

="1000"

maximum

="3000"

value

="1500"

labels

="[1000,2000,3000]"

livedragging

="true"

showtrackhighlight

="true"

snapinterval

="100"

tickinterval

="500"

datatipprecision

="0"

/>

>

<

mx:box

id="box"

width

="100%"

height

="100%"

backgroundcolor

="halosilver"

alpha

="0.0"

/>

>

跑馬燈效果

cgrect frame labelshow.frame frame.origin.x 180 labelshow.frame frame uiview beginanimations testanimation context null uiview setanimationduration 8....

跑馬燈效果

一句話概括,平移再畫一次。textview 預設就支援跑馬燈效果,但需要設定一些東西,滿足一些條件。但我想知道它的原理。看這效果,就是平滑移動 textview 的內容,這不就是 mscrollx 幹的嗎,結合 valueanimator 很容易就實現了。難點在於,把文字的頭部重新從右邊開始畫出來。...

跑馬燈效果

android ellipsize marquee android marqueerepeatlimit marquee forever android singleline true 但是這樣子有乙個缺點,就是這種狀態的跑馬燈只能在textview處於焦點狀態的時候,它才會滾動,對於實際的開發應用...