📄 drawer.as
字号:
} else { child.reset(); child.drawBy(); } if(isCurve(child)) child.initControlPoints(); if(this.redraw) { child.setInitialized(false); } child.movieclip = origMC; child.lineStyle(lineThickness, lineRGB, lineAlpha, linePixelHinting, lineScaleMode, lineCaps, lineJoints, lineMiterLimit); lastChild = child; } } private function getAnimateDetails(start:Number, end:Number, childsArr:Array):Object { var child:Object var backwards:Boolean; if(start > end) { backwards = true; } else { backwards = false; } /* * To compute start and end values for all childs combined, * I first compute the childs where the tween will start and end. (rule of three) * The integer part of the number posStart and posEnd represents that. * The fractional part of those numbers represent the percentage to be animated in integer child. */ var i:Number, len:Number = this.childsArr.length; var posStart:Number = start / 100 * (len); var posEnd:Number = end / 100 * (len); var roundedPosStart:Number = Math.floor(posStart); var roundedPosEnd:Number = Math.floor(posEnd); var start_loc:Number; if(posStart > roundedPosStart) { start_loc = (posStart - roundedPosStart) * 100; } else { if(backwards) { roundedPosStart--; start_loc = 100; } else { start_loc = 0; } } var end_loc:Number; if(posEnd > roundedPosEnd) { end_loc = (posEnd - roundedPosEnd) * 100; } else { if(backwards) { end_loc = 0; } else { roundedPosEnd--; end_loc = 100; } } this.position = roundedPosStart+1; //apply animate state to all children. for (i = 0; i < len; i++) { child = this.childsArr[i]; if(!this.redraw) { child.mode = "DRAWTO"; } if(backwards) { if(i > roundedPosStart) { child.setCurrentPercentage(0); } else { child.setCurrentPercentage(100); } } } for (i = len-1; i > -1; i--) { child = this.childsArr[i]; if(!this.redraw) { child.mode = "DRAWTO"; } if(!backwards) { if(i < roundedPosStart) { child.setCurrentPercentage(100); } else { child.setCurrentPercentage(0); } } child.addEventListener(AnimationEvent.UPDATE, onUpdate); } //reset succossors. this.sequenceArr = new Array(); var percentages:Array = new Array(); //for forward tweening for (i = roundedPosStart; i < roundedPosEnd; i++) { child = childsArr[i]; this.sequenceArr.push(this.childsArr[i+1]); child.addEventListener(AnimationEvent.END, onEnd); if(i == roundedPosStart) { percentages[i] = {start:start_loc, end:100}; } else { percentages[i] = {start:0, end:100}; } } //for backward tweening for (i = roundedPosStart; i > roundedPosEnd; i--) { child = childsArr[i]; this.sequenceArr.push(this.childsArr[i-1]); child.addEventListener(AnimationEvent.END, onEnd); if(i == roundedPosStart) { percentages[i] = {start:start_loc, end:0}; } else { percentages[i] = {start:100, end:0}; } } child = childsArr[roundedPosEnd]; child.addEventListener(AnimationEvent.END, onEnd); if(backwards) { percentages[roundedPosEnd] = {start:100, end:end_loc}; } else { percentages[roundedPosEnd] = {start:0, end:end_loc}; } var details:Object = new Object(); details.backwards = backwards; details.position = roundedPosStart+1; details.roundedPosStart = roundedPosStart; details.roundedPosEnd = roundedPosEnd; details.percentages = percentages; return details; } public function onStart(event:AnimationEvent):void { this.dispatchEvent(new SequenceEvent(AnimationEvent.START, this.getStartValue(), this.childDuration)); } public function onUpdate(event:AnimationEvent):void { this.dispatchEvent(new SequenceEvent(AnimationEvent.UPDATE, this.getCurrentValue(), this.childDuration)); } public function onEnd(event:AnimationEvent):void { event.currentTarget.removeEventListener(AnimationEvent.END, onEnd); var successor:IOutline = this.sequenceArr.shift(); if(successor == null) { this.setTweening(false); this.duration = 0; this.dispatchEvent(new SequenceEvent(AnimationEvent.END, this.getEndValue(), NaN, IAnimatable(event.target), null)); } else { /*backwards will only be true in Sequence mode JOIN*/ if(this.animateMode == Drawer.JOIN && this.backwards) { this.position--; } else { this.position++; } this.currentChild = successor; this.childDuration = IAnimatable(successor).duration; if(this.redraw) { IAnimatable(successor).movieclip.graphics.clear(); IAnimatable(successor).movieclip.graphics.lineStyle(IDrawable(successor).lineThickness, IDrawable(successor).lineRGB, IDrawable(successor).lineAlpha, IDrawable(successor).linePixelHinting, IDrawable(successor).lineScaleMode, IDrawable(successor).lineCaps, IDrawable(successor).lineJoints, IDrawable(successor).lineMiterLimit); } this.dispatchEvent(new SequenceEvent(SequenceEvent.UPDATE_POSITION, this.getCurrentValue(), this.childDuration, IAnimatable(event.target), IAnimatable(successor))); var animateMeth:String; if(this.redraw) { animateMeth = "animate"; } else { animateMeth = "animateTo"; } var _successor:* = successor; if(isCurve(_successor)) _successor.initControlPoints(); _successor.setInitialized(true); successor[animateMeth].apply(successor, [this.percentages[this.position-1].start, this.percentages[this.position-1].end]); this.myAnimator = IAnimatable(successor).myAnimator; } } override public function lineStyle(thickness:Number = 1.0, color:uint = 0, alpha:Number = 1.0, pixelHinting:Boolean = false, scaleMode:String = "normal", caps:String = null, joints:String = null, miterLimit:Number = 3):void { super.lineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit); var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { this.childsArr[i].lineStyle(thickness, color, alpha, pixelHinting, scaleMode, caps, joints, miterLimit); } } override public function animationStyle(duration:Number, easing:* = null):void { super.animationStyle(duration, easing); var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { this.childsArr[i].animationStyle(duration, easing); } this.duration = duration; } public function setAnimateMode(animateMode:String):Boolean { if(animateMode == Drawer.EACH || animateMode == Drawer.JOIN) { this.animateMode = animateMode; } else { return false; } var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { var child:Object = this.childsArr[i]; if(child is Drawer) { child.setAnimateMode(animateMode); } } return true; } public function getAnimateMode():String { return this.animateMode; } public function getChild():IOutline { return IOutline(this.currentChild); } public function getChildren():Array { return this.childsArr; } public function getNextChild():IOutline { if(this.animateMode == Drawer.JOIN && this.backwards) { return IOutline(this.childsArr[this.position-2]); } else { return IOutline(this.childsArr[this.position]); } } public function getPreviousChild():IOutline { if(this.animateMode == Drawer.JOIN && this.backwards) { if(this.position-1 == this.childsArr.length) { return IOutline(this.childsArr[this.position-1]); } else { return IOutline(this.childsArr[this.position]); } } else { return IOutline(this.childsArr[this.position-2]); } } public function getChildDuration():Object { return this.childDuration; } public function addChild(component:IOutline):IOutline { this.childsArr.push(component); return component; } public function removeChild(component:IOutline):void { var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { if(this.childsArr[i] == component) { this.childsArr.splice(i, 1); } } } override public function clear():void { var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { var child:Object = this.childsArr[i]; child.mc.graphics.clear(); } this.fillMovieclip.graphics.clear(); } override public function accept(visitor:IVisitor):void { var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { visitor.visit(this.childsArr[i]); } } public function get lineMovieclip():Sprite { return this.m_lineMovieclip; } public function set lineMovieclip(m_lineMovieclip:Sprite):void { this.m_lineMovieclip= m_lineMovieclip; } public function get fillMovieclip():Sprite { return this.m_fillMovieclip; } public function set fillMovieclip(m_fillMovieclip:Sprite):void { this.m_fillMovieclip= m_fillMovieclip; } override public function setOptimizationMode(optimize:Boolean):void { this.equivalentsRemoved = optimize; var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { this.childsArr[i].setOptimizationMode(optimize); } } override public function setTweenMode(tweenMode:String):Boolean { super.setTweenMode(tweenMode); var isSet:Boolean; var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { isSet =this.childsArr[i].setTweenMode(tweenMode); } return isSet; } override public function setDurationMode(durationMode:String):Boolean { super.setDurationMode(durationMode); var isSet:Boolean; var i:Number, len:Number = this.childsArr.length; for (i = 0; i < len; i++) { isSet = this.childsArr[i].setDurationMode(durationMode); } return isSet; } override public function getStartValue():Number { var startValue:Number = super.getStartValue(); if(isNaN(startValue)) { startValue = 0; } return startValue; } override public function getEndValue():Number { var endValue:Number = super.getEndValue(); if(isNaN(endValue)) { endValue = 100; } return endValue; } override public function getCurrentValue():Number { return this.position; } override public function getCurrentPercentage():Number { var pos:Number = this.getCurrentValue()-1; var perc:Number = this.currentChild.getCurrentPercentage(); if(isNaN(perc)) { perc = 0; } if(this.animateMode == Drawer.EACH && this.backwards == true) { pos = this.getEndValue() - (pos - (this.getStartValue() - 1)); } var currentValue:Number = pos + perc / 100; var currentPerc:Number = currentValue / (this.childsArr.length) * 100; return currentPerc; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -