Flash special Effects production common source code sharing

Source: Internet
Author: User
Tags abs cos md5 pow setinterval
Flash software for users to share the details of the special effects produced commonly used source code.
Tutorial Sharing:
Source
Array of objects
For example, to build an array with many attributes, it's easy to do this:
The following is a reference fragment:
Vara:array=newarray ();
for (vari=0;i<10;i++) {
A[i]=newobject ();
a[i].x=10;
A[i].y=10*i;
A[i].name= "---";
A[i].id=i;
Give me whatever attribute you want.
}
It is better to store objects with local variables first.
Vara=newarray ()
for (vari=0;i<10;i++) {
Varta=newobject ();
ta.x=10;
ta.y=10;
Ta.name= "n" +i;
A.push (TA);
}
Or a simpler way:
Vara=newarray ()
for (vari=0;i<10;i++) {
A[i]={x:10,y:10,name: "N" +i}
}
Program Control role Movement
The following code controls the MovieClip MC from (50,50) transverse motion to (100,50) stop, at a speed of 5 pixel:
The following is a reference fragment:
mc._x=mc._y=50;
Mc.onenterframe=function () {
_x+=5;
Trace (_x);
if (_x==100) {
Delete (mc.onenterframe);
}
};
Accurate timing
We set the time to 60 seconds and then periodically (1000milliseconds) by setinterval to trigger a function Runtimer.
function Runtimer is used for timing, and when the time is up, turn to execute outthere.
function Outthere is used to process the time to the next action, do not forget Clearinterval (intervalid), stop timing.
The following is a reference fragment:
vartime:number=60;
Varintervalid:number;
Intervalid=setinterval (runtimer,1000);
Functionruntimer () {
time--;
Trace (time);
if (time==0) {
Outthere ();
}
}
Functionoutthere () {
Blahblahblah
Clearinterval (Intervalid);
}
Find the currently smallest available depth Depth (from abroad)
For Flash Player 6:
The following is a reference fragment:
Availtopdepth=function () {
Varalldepths=[];
for (Varzin_root) {
if (_root[z]instanceofbutton| | _root[z]instanceofmovieclip| | _root[z]instanceoftextfield) {
Alldepths.push (_root[z].getdepth ());
}
}
if (alldepths.length!=0) {
Sortall=function (a,b) {if (ab) {return1;} Else{return0;};
Alldepths.sort (Sortall);
Return (parseint (alldepths[alldepths.length-1]) +1);
}
};
Trace (_root.availtopdepth ()), placing a MovieClip in Stage, and then executing the Action will get the closest available depth. We can also use this to create absolutely no
The MovieClip that will go wrong, such as:
_root.createemptymovieclip ("Mc_name", availtopdepth ());
Getnexthighestdepth () and getinstanceatdepth (depth) are for player 7.
Mouse blanking
After the mouse disappears, right health pop-up menu, the mouse appears again, and has been retained ~
The complete solution is: In the Zuojian lift, the right to the second lift, the return key to lift the time to hide the mouse again.
The complete approach is complex, and here's a simple solution to the vast majority of problems:
The following is a reference fragment:
Nenterframe=function () {
if (Key.isdown (1) | | | Key.isdown (Key.enter)) {
Mouse.hide ();
}
}
I often use an acceleration to move the code
The following is a reference fragment:
The following code is placed in the first frame of the main scene
Stop ();
_global.a=5;
Move the acceleration, the bigger the slower
_global.click_x=0;
Used to record the location of the mouse click
_global.click_y=0;
_root.onmousedown=function () {
_global.click_x=_root._xmouse;
_global.click_y=_root._ymouse;
Me is the instancename of controlled MC
Me.onenterframe=function () {
if (Math.Abs (_global.click_x-me._x) <2&&math.abs (_global.click_y-me._y) <2) {
If you have basically moved to the point where the mouse has been positioned, then cancel the handler for this event handle.
Delete (this.onenterframe);
Return
}else{
Control movement
me._x+= (_global.click_x-me._x)/_GLOBAL.A;
me._y+= (_global.click_y-me._y)/_GLOBAL.A;
}
};
};
The following sections are optional
A_v is a text box that can be entered to enter the acceleration, that is, can be customized speed, easy to debug
A_v.onchanged=function () {
if (a_v.text== "" | | Number (A_v.text) >1000| | Number (A_v.text) <0) {
DefaultValue
a_v.text=5;
}else{
_global.a=number (a_v.text)? Number (A_v.text): 5;
Trace (_GLOBAL.A);
}
};
Random output from 1 to 100 without a duplicate statement:
The following is a reference fragment:
Seq=newarray (100);
Parray=newarray (100);
Functionmakerandom () {
for (i=1;i<=100;i++) {
Seq[i]= "A";
}
}
Functionmrandom () {
while (true) {
N=int (random (100)) +1;
if (seq[n]== "A") {
seq[n]= "0";
Break
}
}
return (n);
}
Functionrarray () {
for (i=1;i<=100;i++) {
Parray[i]=mrandom ();
Trace (Parray[i]);
}
}
Stop ();
Cynical
We can use this technique to add something outside of some functions without having to understand the code of the function ~ ~
For example, if there is a lot of MC covering the Onenterframe function, we can know the onenterframe of the MC under _root
In what order the numbers are executed:
Code:
The following is a reference fragment:
for (Variin_root) {
if (_root[i].onenterframe!=null) {//If the object implements the Onenterframe interface
_root[i].oldfunc=_root[i].onenterframe;//first to save the original Onenterframe handle
_root[i].onenterframe=function () {//then began to replace the ~ ~ plus a Shell ~ ~
Trace (this+ ": onenterframecalled.");
This.oldfunc ()//We invoke the original function with a reserved handle
Trace (this+ ": onenterframereturned.");
}
}
}
If you want to cancel these additional actions:
Code:
The following is a reference fragment:
for (Variin_root) {
if (_root[i].oldfunc!=null) {//if found to have changed traces
_root[i].onenterframe=_root[i].oldfunc;
Delete (Oldfunc);
}
}
Oh, the key to these operations is the reference mechanism in Flash:
All function names are references, and functions themselves float in the ocean of data. If no variable references him, he will be recycled. If so,
He's not going to be recycled. So there's an interesting thing about this: the delete function doesn't erase anything except the name that you want to delete: (and Java
The mechanism is similar, but differs from c)
The following is a reference fragment:
A=function () {Trace ("functionacalled");}
B=a;
Delete (a); nothing happens except the name of a is deleted
b ();
function to get an instance of its caller through this.
Movieclipplus.as
Defines a few simple MC operations
Draw points: Because Flash does not draw points, then we will draw a short-term
The following is a reference fragment:
Movieclip.prototype.point=oxmovieclippoint;
Functionoxmovieclippoint (x,y) {
This.moveto (X,y);
This.lineto (X+1,y);
}
Draw Rectangle, upper left corner x1,y1 lower right corner x2,y2, RGB color, opacity alpha
The following is a reference fragment:
Movieclip.prototype.rect=oxmoviecliprect;
Functionoxmoviecliprect (X1,y1,x2,y2,rgb,alpha) {
This.beginfill (Rgb,alpha);
This.moveto (X1,Y1);
This.lineto (X1,Y2);
This.lineto (X2,Y2);
This.lineto (X2,Y1);
This.lineto (X1,Y1);
This.endfill ();
}
Draw Circle: So BT of course not I wrote, the author of the vegetarian Jodykeating
Center X,y, Radius r
Movieclip.prototype.circle=oxmovieclipcircle;
Functionoxmovieclipcircle (x,y,r) {
vara=r*0.414213562;
varb=r*0.707106781;
This.moveto (X+r,y);
This.curveto (X+r,y-a,x+b,y-b);
This.curveto (X+A,Y-R,X,Y-R);
This.curveto (X-a,y-r,x-b,y-b);
This.curveto (X-r,y-a,x-r,y);
This.curveto (X-R,Y+A,X-B,Y+B);
This.curveto (X-A,Y+R,X,Y+R);
This.curveto (X+A,Y+R,X+B,Y+B);
This.curveto (X+r,y+a,x+r,y);
}
A line move between two points
The following is a reference fragment:
vars=15;
_root.onmousedown=function () {
Varoldm_x=_root._xmouse;
Varoldm_y=_root._ymouse;
ax=aa._x;
ay=aa._y;
Dis=math.sqrt ((oldm_x-ax) * (Oldm_x-ax) + (oldm_y-ay) * (Oldm_y-ay));
Xa= (Oldm_x-ax)/dis;
Ya= (Oldm_y-ay)/dis;
Amove ();
};
Functionamove () {
Nenterframe=function () {
Aa._x+=s*xa;
Aa._y+=s*ya;
if (MATH.SQRT (aa._x-ax) * (Aa._x-ax) + (aa._y-ay) * (Aa._y-ay)) >dis) {
Deleteonenterframe;
}
};
}
Calculates the distance between two objects/two points (registration point)
The following is a reference fragment:
Functiongetdistanceof (target1,target2,x2,y2) {
if (arguments.length==4) {
Dx=x2-target1;
Dy=y2-target2;
}elseif (arguments.length==2) {
dx=target2._x-target1._x;
dy=target2._y-target1._y;
}
RETURNMATH.SQRT (Dx*dx+dy*dy);
}
The Arguments object is an array that contains values that are passed as arguments to any function. Every time a function is called in an action script, the letter
The number of Arguments objects is created automatically. You also create a local variable arguments that allows you to reference the arguments object.
Let the playing MC suspend for some time
The following is a reference fragment:
Functionpauseplay (sec) {
Pfunc=function () {
This.play ();
Clearinterval (This.pint);
}
Stop ();
This.pint=setinterval (This, "Pfunc", sec*1000);
}
This call. The SEC is a paused time, in seconds.
Pauseplay (2);
Onhittest (target), a MC event written by itself, triggers an event when the MC is hittest with the specified MC. In fact, there is no special place, but also with setinterval to achieve
The following is a reference fragment:
Stop ();
Movieclip.prototype.listen=function (target) {
if (this.ishiting==undefined) {
This.ishiting=this.hittest (target);
}
if (This.hittest (target)) {
if (This.ishiting==false) {
This.broadcastmessage ("Onhittest", This,target)//broadcast events, passing this and target two parameters to an event
}
This.ishiting=true;
}else{
This.ishiting=false;
}
};//adds a domain member listen member for MovieClip to monitor whether the current object collides with the target
Movieclip.prototype.watch=function (target) {
This.timer=setinterval (This, "Listen", 50,target);
};//detects collisions at a rate of 50 milliseconds per test
Movieclip.prototype.unwatch=function () {
Clearinterval (This.timer);
};//to stop monitoring objects
Asbroadcaster.initialize (Movieclip.prototype);//Initialize MovieClip prototype as event source
The following is an example of a call
Suppose there are two movieclip, left ball, right wall, let ball continue to wall move, while monitoring wall, once hit trigger event onhittest
Ball.onenterframe=function () {
this._x+=5;
};//let ball keep moving to the right.
Mylistener=newobject ();
Mylistener.onhittest=function (Source,target) {
Trace ("The" "+source._name+" hit "+target._name+");
};
Ball.addlistener (MyListener)//Create listener and register to Ball
Ball.watch (Wall)//Let ball monitor wall
Flash algorithm for MD5 32-bit code
The following is a reference fragment:
//-----------
FUNCTIONMD5 (s) {
Returnbinl2hex (CORE_MD5 (Str2binl (s), s.length*strsize));
}
FUNCTIONCORE_MD5 (X,len) {
X[len>>5]= (X[len>>5]) | (128<
X[(((len+64) >>>9) <<4) +14]=len;
vara=1732584193;
varb=-271733879;
varc=-1732584194;
vard=271733878;
vari=0;
while (ivarolda=a;
Varoldb=b;
Varoldc=c;
Varoldd=d;
A=MD5_FF (a,b,c,d,x[i+0],7,-680876936);
D=MD5_FF (d,a,b,c,x[i+1],12,-389564586);
C=MD5_FF (c,d,a,b,x[i+2],17,606105819);
B=MD5_FF (b,c,d,a,x[i+3],22,-1044525330);
A=MD5_FF (a,b,c,d,x[i+4],7,-176418897);
D=MD5_FF (d,a,b,c,x[i+5],12,1200080426);
C=MD5_FF (c,d,a,b,x[i+6],17,-1473231341);
B=MD5_FF (b,c,d,a,x[i+7],22,-45705983);
A=MD5_FF (a,b,c,d,x[i+8],7,1770035416);
D=MD5_FF (d,a,b,c,x[i+9],12,-1958414417);
C=MD5_FF (c,d,a,b,x[i+10],17,-42063);
B=MD5_FF (b,c,d,a,x[i+11],22,-1990404162);
A=MD5_FF (a,b,c,d,x[i+12],7,1804603682);
D=MD5_FF (d,a,b,c,x[i+13],12,-40341101);
C=MD5_FF (c,d,a,b,x[i+14],17,-1502002290);
B=MD5_FF (b,c,d,a,x[i+15],22,1236535329);
A=md5_gg (a,b,c,d,x[i+1],5,-165796510);
D=md5_gg (d,a,b,c,x[i+6],9,-1069501632);
C=md5_gg (c,d,a,b,x[i+11],14,643717713);
B=md5_gg (b,c,d,a,x[i+0],20,-373897302);
A=md5_gg (a,b,c,d,x[i+5],5,-701558691);
D=md5_gg (d,a,b,c,x[i+10],9,38016083);
C=md5_gg (c,d,a,b,x[i+15],14,-660478335);
B=md5_gg (b,c,d,a,x[i+4],20,-405537848);
A=md5_gg (a,b,c,d,x[i+9],5,568446438);
D=md5_gg (d,a,b,c,x[i+14],9,-1019803690);
C=md5_gg (c,d,a,b,x[i+3],14,-187363961);
B=md5_gg (b,c,d,a,x[i+8],20,1163531501);
A=md5_gg (a,b,c,d,x[i+13],5,-1444681467);
D=md5_gg (d,a,b,c,x[i+2],9,-51403784);
C=md5_gg (c,d,a,b,x[i+7],14,1735328473);
B=md5_gg (b,c,d,a,x[i+12],20,-1926607734);
A=MD5_HH (a,b,c,d,x[i+5],4,-378558);
D=MD5_HH (d,a,b,c,x[i+8],11,-2022574463);
C=MD5_HH (c,d,a,b,x[i+11],16,1839030562);
B=MD5_HH (b,c,d,a,x[i+14],23,-35309556);
A=MD5_HH (a,b,c,d,x[i+1],4,-1530992060);
D=MD5_HH (d,a,b,c,x[i+4],11,1272893353);
C=MD5_HH (c,d,a,b,x[i+7],16,-155497632);
B=MD5_HH (b,c,d,a,x[i+10],23,-1094730640);
A=MD5_HH (a,b,c,d,x[i+13],4,681279174);
D=MD5_HH (d,a,b,c,x[i+0],11,-358537222);
C=MD5_HH (c,d,a,b,x[i+3],16,-722521979);
B=MD5_HH (b,c,d,a,x[i+6],23,76029189);
A=MD5_HH (a,b,c,d,x[i+9],4,-640364487);
D=MD5_HH (d,a,b,c,x[i+12],11,-421815835);
C=MD5_HH (c,d,a,b,x[i+15],16,530742520);
B=MD5_HH (b,c,d,a,x[i+2],23,-995338651);
A=md5_ii (a,b,c,d,x[i+0],6,-198630844);
D=md5_ii (d,a,b,c,x[i+7],10,1126891415);
C=md5_ii (c,d,a,b,x[i+14],15,-1416354905);
B=md5_ii (b,c,d,a,x[i+5],21,-57434055);
A=md5_ii (a,b,c,d,x[i+12],6,1700485571);
D=md5_ii (d,a,b,c,x[i+3],10,-1894986606);
C=md5_ii (c,d,a,b,x[i+10],15,-1051523);
B=md5_ii (b,c,d,a,x[i+1],21,-2054922799);
A=md5_ii (a,b,c,d,x[i+8],6,1873313359);
D=md5_ii (d,a,b,c,x[i+15],10,-30611744);
C=md5_ii (c,d,a,b,x[i+6],15,-1560198380);
B=md5_ii (b,c,d,a,x[i+13],21,1309151649);
A=md5_ii (a,b,c,d,x[i+4],6,-145523070);
D=md5_ii (d,a,b,c,x[i+11],10,-1120210379);
C=md5_ii (c,d,a,b,x[i+2],15,718787259);
B=md5_ii (b,c,d,a,x[i+9],21,-343485551);
A=safe_add (A,olda);
B=safe_add (B,OLDB);
C=safe_add (C,OLDC);
D=safe_add (D,OLDD);
i=i+16;
}
ReturnArray (A,B,C,D);
}
FUNCTIONMD5_CMN (q,a,b,x,s,t) {
Returnsafe_add (Bit_rol (Safe_add (Safe_add (a,q), Safe_add (X,t)), s), b);
}
Functionmd5_ff (a,b,c,d,x,s,t) {
RETURNMD5_CMN ((b&c) | ( (~b) &d), a,b,x,s,t);
}
Functionmd5_gg (a,b,c,d,x,s,t) {
RETURNMD5_CMN ((b&d) | ( c& (~d)), a,b,x,s,t);
}
FUNCTIONMD5_HH (a,b,c,d,x,s,t) {
RETURNMD5_CMN ((b^c) ^d,a,b,x,s,t);
}
Functionmd5_ii (a,b,c,d,x,s,t) {
RETURNMD5_CMN (c^ (b|) ( ~d)), a,b,x,s,t);
}
Functionsafe_add (x,y) {
Varlsw= (x&65535) + (y&65535);
Varmsw= ((x>>16) + (y>>16)) + (LSW>>16);
Return (MSW<<16) | (lsw&65535);
}
Functionbit_rol (num,cnt) {
Return (num<>> (32-cnt));
}
Functionstr2binl (str) {
Varbin=array ();
Varmask= (1<
vari=0;
while (i< (str.length*strsize)) {
Bin[i>>5]= (Bin[i>>5]) | ((Str.charcodeat (i/strsize) &mask) <
I=i+strsize;
}
Returnbin;
}
Functionbinl2hex (BinArray) {
if (hexcase) {
}else{
}
varhex_tab= "0123456789abcdef";
Varstr= "";
vari=0;
while (i< (binarray.length*4)) {
Str=str+ (Hex_tab.charat ((binarray[i>>2)) >> ((i%4*8) +4) &15) +hex_tab.charat (((binarray[i
>>2]) >> (i%4*8)) (&15));
i++;
}
RETURNSTR;
}
varhexcase=0;
varstrsize=8;
--------above without modification,
B=MD5 ("xx");
XX can be set to any character
S=b.touppercase ();
Convert to uppercase
Trace (b);
Trace (s);
The send-point easing function is the following reference fragment:
Math.lineartween=function (t,b,c,d) {
Returnc*t/d+b;
};
Linear motion function
Math.easeinquad=function (t,b,c,d) {
returnc* (T/=d) *t+b;
};
Two-time slow-entry function
Math.easeoutquad=function (t,b,c,d) {
return-c* (T/=d) * (t-2) +b;
};
Two time delay function
Math.easeinoutquad=function (t,b,c,d) {
if ((T/=D/2) <1) {
Returnc/2*t*t+b;
}
Return-c/2* ((--t) * (t-2)-1) +b;
};
Two-time easing function
Math.easeincubic=function (t,b,c,d) {
Returnc*math.pow (t/d,3) +b;
};
Three-time slow-entry function
Math.easeoutcubic=function (t,b,c,d) {
returnc* (Math.pow (t/d-1,3) +1) +b;
};
Three time delay function
Math.easeinoutcubic=function (t,b,c,d) {
if ((T/=D/2) <1) {
Returnc/2*math.pow (t,3) +b;
}
Returnc/2* (Math.pow (t-2,3) +2) +b;
};
Three-time easing function
Math.easeinquart=function (t,b,c,d) {
Returnc*math.pow (t/d,4) +b;
};
Four-time slow-entry function
Math.easeoutquart=function (t,b,c,d) {
return-c* (Math.pow (t/d-1,4)-1) +b;
};
Four time delay function
Math.easeinoutquart=function (t,b,c,d) {
if ((T/=D/2) <1) {
Returnc/2*math.pow (t,4) +b;
}
Return-c/2* (Math.pow (t-2,4)-2) +b;
};
Four-time easing function
Math.easeinquint=function (t,b,c,d) {
Returnc*math.pow (t/d,5) +b;
};
Five-time slow-entry function
Math.easeoutquint=function (t,b,c,d) {
returnc* (Math.pow (t/d-1,5) +1) +b;
};
Five Time delay function
Math.easeinoutquint=function (t,b,c,d) {
if ((T/=D/2) <1) {
Returnc/2*math.pow (t,5) +b;
}
Returnc/2* (Math.pow (t-2,5) +2) +b;
};
Five-time easing function
Math.easeinsine=function (t,b,c,d) {
returnc* (1-math.cos (t/d* (MATH.PI/2)) +b;
};
Sinusoidal Slow out function
Math.easeoutsine=function (t,b,c,d) {
Returnc*math.sin (t/d* (MATH.PI/2)) +b;
};
Sinusoidal Slow out function
Math.easeinoutsine=function (t,b,c,d) {
Returnc/2* (1-math.cos (math.pi*t/d)) +b;
};
Sine easing function
Math.easeinexpo=function (t,b,c,d) {
Returnc*math.pow (2,10* (t/d-1)) +b;
};
Exponential easing function
Math.easeoutexpo=function (t,b,c,d) {
returnc* (-math.pow (2,-10*t/d) +1) +b;
};
Exponential slow out function
Math.easeinoutexpo=function (t,b,c,d) {
if ((T/=D/2) <1) {
Returnc/2*math.pow (2,10* (t-1)) +b;
}
Returnc/2* (-math.pow (2,-10*--t) +2) +b;
};
Exponential easing function
Math.easeincirc=function (t,b,c,d) {
returnc* (1-math.sqrt (t/=d) *t) +b;
};
Circular easing function
Math.easeoutcirc=function (t,b,c,d) {
Returnc*math.sqrt (t=t/d-1) *t) +b;
};
Circular slow out function
Math.easeinoutcirc=function (t,b,c,d) {
if ((T/=D/2) <1) {
Returnc/2* (1-math.sqrt (1-t*t)) +b;
}
Returnc/2* (Math.sqrt (t-=2) *t) +1 +b;
};
Circular ease out function
Well, the above information is small to give you the flash of this software users to bring the detailed special effects of the production of common source code to share the whole content, you see the software users here, small series believe that everyone now that is very clear it, I hope that the content of the above share can give you the users of Flash software to bring useful help.

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.