As3 Microsoft performance database development diary (III)-improved architecture

Source: Internet
Author: User

I did not expect a major change to the Framework so soon. With reference to some other open-source libraries, I plan to improve the architecture and remove it from tweenlite.

The improved architecture has the following ideas:

1. each effect has a setprogressimp method. This method has a parameter progress with a value range of 0-1. The method mainly implements the effect transformation. Progress indicates the effect, and 0 indicates the beginning, 1 is complete

2. set a timer with a wireless cycle interval of 20 milliseconds. Call the update method after each timer event is triggered. This method generates a progress value based on the current time, start time, and end time, and calls the setprogressimp method.

After switching to this architecture, you can set the progress to be different from the animation to exit. The progress to go to progress is from 0 to 1, and the progress to exit is from 1 to 0. This avoids repeated code, the idea of entering and exiting the animation effect is basically the same.

If I leave tweenlite, it makes my development more independent. I only need to rewrite setprogressimp for each effect.

During the software development process, changes cannot be avoided. As the development continues to deepen, the system realizes the shortcomings of the existing architecture and then seeks a better method and architecture.

The Code is as follows:

In the parent class, write the framework and call structure. In the subclass, you only need to override some methods.

Parent class entrance:

package com.msanimation.entrance{    import com.msanimation.Animation;    import com.msanimation.MSMask;        import flash.display.DisplayObject;    import flash.events.Event;    import flash.events.EventDispatcher;    import flash.events.MouseEvent;    import flash.events.TimerEvent;    import flash.utils.Timer;    import flash.utils.getTimer;        public class Entrance extends EventDispatcher implements Animation{        protected var target:Object;        protected var json:Object;        protected var mask:MSMask;        protected var delay:Timer;        protected var timer:Timer;        protected var startTime:Number;        protected var endTime:Number;        protected var progress:Number;                public function Entrance(target:Object,json:Object){            this.target=target;            this.json=json;            DefaultJson();            Initialization();            if(this.json.autoplay){                Start();            }        }                protected function DefaultJson():void{            json=json==null?{}:json;            json.delay=json.delay==null?0:json.delay;            json.autoplay=json.autoplay==null?false:json.autoplay;            json.exit=json.exit==null?false:json.exit;        }                public function Initialization():void{            delay=new Timer(json.delay,1);            timer=new Timer(20,0);            delay.addEventListener(TimerEvent.TIMER_COMPLETE,OnProgress);            timer.addEventListener(TimerEvent.TIMER,Update);        }                protected function OnProgress(e:Event):void{            delay.removeEventListener(TimerEvent.TIMER_COMPLETE,OnProgress);            startTime=getTimer()*0.001;            endTime=startTime+json.duration;            timer.start();        }                protected function Update(e:Event):void{            progress=(0.001*getTimer()-startTime)/(endTime-startTime);            progress=json.exit?1-progress:progress;            SetProgress(progress);        }                public function Reset():void{            progress=json.exit?1:0;        }                        public function Start():void{            delay.start();        }                protected function SetProgress(progress:Number):void{            target.visible=true;            if(progress<0 || progress>1){                timer.stop();                timer.removeEventListener(TimerEvent.TIMER,Update);                Complete();            }else{                SetProgressImp(progress)            }        }                protected function Complete():void{            target.visible=json.exit?false:true;            dispatchEvent(new Event("ANIMATION.COMPLETE"));        }                protected function SetProgressImp(progress:Number):void{        }    }}

Subclass flyin (fly in animation), override initialization and setprogressimp:

Package COM. msanimation. entrance {import flash. display. displayobject; import flash. events. event; import flash. events. timerevent; import flash. utils. timer; import flash. utils. gettimer; import flashx. textlayout. elements. breakelement; public class flyin extends entrance {private var destx: int; // target coordinate private var desty: int; private var orix: int; // start coordinate private var oriy: int; public Function flyin (target: object, JSON: Object = NULL) {super (target, JSON);} override public function initialization (): void {super. initialization (); target. visible = false; destx = target. x; desty = target. y; Switch (JSON. direction) {// corresponds to case "bottom": orix = target. x; oriy = target. Y + 200; break; Case "bottom-left": orix = target. A x-200; oriy = target. Y + 200; break; Case "bottom-Right": orix = target. X + 200; oriy = target. Y + 200; break; Case "Left": orix = target. x-200; break; Case "right": orix = target. X + 200; break; Case "TOP": oriy = target. y-200; break; Case "top-left": orix = target. A x-200; oriy = target. y-200; break; Case "Top-Right": orix = target. A x-200; oriy = target. y-200; break; default: orix = target. x; oriy = target. Y + 200 ;}} override protected function setprogressimp (Progress: Number): void {target. X = orix + (destx-orix) * progress; // calculates the target coordinate based on progress. y = oriy + (desty-oriy) * progress;} override protected function defaultjson JSON (): void {super. defajson JSON (); JSON. duration = 0.5 ;}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.