Source analysis of random moving balls in Flash

Source: Internet
Author: User
Tags square root

Draw a circle on the stage to convert to a movie clip symbol, the instance name is MC, and the following code is added in the first frame:

function Fanhui (x1, x2, y1, y2) {//compute and return the square root of the defined coordinates and object coordinates added

Sqrt = Math.sqrt (x1+x2+y1+y2);

return Sqrt;

}

function Chushizhi (obja) {

EndX = random (550);//x coordinates defined

EndY = random (400);//x coordinates defined

D = Fanhui (EndX, EndY, obja._x, obja._y);//Get the square root after return

DX = (endx-obja._x)/d*t;//defines the x-coordinate to which an object is to be moved

DY = (endy-obja._y)/d*t;//defines the y-coordinate to which an object is to be moved

}

function tt () {//define the speed of movement

t = random (10);

}

function Yidong (OBJB) {//object move

objb._x = OBJB._X+DX;

objb._y = Objb._y+dy;

}

function Movie (obj) {

if (EndX = = undefined) {//if the defined x coordinate is null execution

TT ();//Running Speed function

Chushizhi (obj);//run definition coordinate function

else if (obj._x>0 && obj._y>0 && obj._x<550 && obj._y<400) {//If the object's coordinates are in the 500* 400 size of the stage in the execution

Yidong (obj);//Run object move function

else {///object coordinates beyond the stage redefine a coordinate in the stage and move to that place

TT ();

Chushizhi (obj);

Trace (ENDX);

Yidong (obj);

}

}

Onenterframe = function () {

Movie (MC);

};

This example mainly demonstrates the transfer application of the parameter, because I didn't understand the parameters at all (although I don't know much now), but for myself there is a new understanding and simple application, to dedicate this to me and the same novice, remember to look at the function in parentheses several times, you will find that they have a certain regularity. I am a child, wish everybody good evening!

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.