一個很常用的資料表示方式
為了方便以後使用
所以乾脆就寫成一個CLASS
調用的時候只要
1 2 | var itemCocept:scrollText = new scrollText(width, height, TXT); addChild(itemCocept); |
當文字內容超過指定的高度
就會自動生成scroll bar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | package justfly.vo{ import flash.events.*; import flash.display.*; import flash.text.TextField; import flash.text.TextFormat; import flash.text.TextFieldAutoSize; import flash.text.AntiAliasType; import flash.text.GridFitType; import flash.geom.Rectangle; import caurina.transitions.Tweener; import justfly.dao.*; import justfly.ui.*; import justfly.util.*; import justfly.vo.*; public class scrollText extends Sprite { var mod:ModelLocator = ModelLocator.getInstance(); var areaH:int; var areaW:int; var mainString:String; var format:TextFormat = new TextFormat(); var mask_scrollText:Sprite; var tab_bar:Sprite; var Rec:Rectangle; var avable:int; var nowhave:int; var conceptTxt:TextField; var pix:int = 10; public function scrollText(w:int, h:int, txt:String) { areaH = h; areaW = w; mainString = txt; addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event) { removeEventListener(Event.ADDED_TO_STAGE, init); format.size = 11; conceptTxt = createTextField(0, 0, format, mainString, TextFieldAutoSize.LEFT, GridFitType.PIXEL); mask_scrollText = new Sprite(); mask_scrollText.graphics.beginFill(0x000000); mask_scrollText.graphics.drawRect(0, 0, areaW, areaH); mask_scrollText.graphics.endFill(); addChild(mask_scrollText); mask = mask_scrollText; if (conceptTxt.height > areaH) setScroll(); } private function createTextField(x:Number,y:Number,fm:TextFormat,tl:String,tfs:String,gft:String):TextField { var result:TextField = new TextField(); result.textColor = 0xFFFFFF; result.x = x; result.y = y; //result.embedFonts = true; result.wordWrap = true; result.selectable = false; result.antiAliasType = AntiAliasType.ADVANCED; result.text = tl; result.autoSize = tfs; result.gridFitType = gft; result.setTextFormat(fm); result.width = areaW; addChild(result); return result; } private function setScroll() { Tweener.addTween(conceptTxt, { width: areaW - 10, time:0.2, transition:"linear", onComplete:function() { avable = Math.floor(areaH / pix); nowhave = Math.floor(conceptTxt.height / pix); tab_bar = new Sprite(); tab_bar.graphics.beginFill(0xFFFFFF); tab_bar.graphics.drawRect(areaW - 8, 0, 6, areaH * (nowhave-avable) / avable); tab_bar.graphics.endFill(); tab_bar.buttonMode = true; addChild(tab_bar); Rec = new Rectangle(0, 0, 0, areaH - tab_bar.height); tab_bar.addEventListener(MouseEvent.MOUSE_DOWN, tabDown); }} ); } private function tabDown(e:MouseEvent) { tab_bar.startDrag(false, Rec ); tab_bar.addEventListener(Event.ENTER_FRAME, dispatchNavScroll ); parent.addEventListener(MouseEvent.MOUSE_UP, tabUP); } private function tabUP(e:MouseEvent) { tab_bar.stopDrag(); tab_bar.removeEventListener(Event.ENTER_FRAME, dispatchNavScroll); parent.removeEventListener(MouseEvent.MOUSE_UP, tabUP); } private function dispatchNavScroll(e:Event) { var goAtY:int = Math.floor(tab_bar.y / (nowhave-avable)); Tweener.addTween(conceptTxt, { y: -10 * goAtY, time:0.2, transition:"linear"}); } } } |
您好:
我是初學者,請問這有範例可以寄給我研究嗎?
mandy007@mail.tbcnet.net
感謝~~
這就只有一個class耶
效果可以看http://mensegg-black-store.jp/itemdetail/525