Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! · Link to Us · Newsletter · Tell a Friend ·

      Add Tutorial |

 

Advertise here

Create Speaking Characters for your website and Flash movies. 15 Day Free Trial




PHP Scripts

 

 Home > Tutorials  > ActionScript

How to create randomly flying away movie

Author: Sergiy Kamenyev | Email
Website : www.vemix.com


Advertisement


Then, α will equal arctangent of this value, and due to stupidity of arctangent function (:),
we have to add π if XFA lesser than XB.
Everything is fine, if XFA does not equal to XB.
If they are same (vertical "up" or "down" movement), the angle α equals to π/2 if movement is up, and π/2 + π, if it is down.
Third degree polynomial can have three roots. The first will be 0 in turned coordinates, third - XsRFA (see pic.2 and/or pic.3) and lines 55-58.



Second root we shall pick randomly from the interval (0, XsRFA) (lines 61-65).
In lines 68-75 we adjust "elder" coefficient of our polynomial so that the trajectory of flying will not go far from segment [XB lesser than XFA].
In the line 78 we assign X-step of moving by QXsC that should be assigned on the _parent of our flying movie.
Pay attention to the function polRan(XsC), that calculates the result of our polynomial in any point XsC in turned coordinates.

After calling findPolynomialRandomly() function, we assign 0 to IRun (line 24), that means that our flying button-movie will begin to move (look at lines 89-90).
The movement will be calculated by the function moveThis().
It is simple enough to understand just by reading of its code.

Now, let's describe small code on the first and unique frame of _root.

r1 //Bounds of possible appearance of the button-movie named by "mvFA"
r2 var XMin=mvFA._width/2+1,XMax=550-mvFA._width/2-1,
r3 YMin=mvFA._height/2+1,YMax=400-mvFA._height/2-1;
r4 //Initialize all
r5 cbFinished(mvFA);
r6 /*f***************/
r7 function cbFinished(mvK)
r8 {
r9 //Place destination movie named by "mvPoint" randomly
r10 mvPoint._x=random(550);
r11 mvPoint._y=random(400);
r12
r13 mvK.QXsC=24; //Assign number of steps
r14
r15 //Assign destination-variables to the button-movie
r16 mvK.XFA=mvPoint._x;
r17 mvK.YFA=mvPoint._y;
r18
r19 //Restore scales of the button-movie
r20 mvK._yscale=mvK._xscale=100;
r21
r22 //Place button-movie randomly
r23 mvK._x=XMin+random(XMax-2*XMin+1);
r24 mvK._y=YMin+random(YMax-2*YMin+1);
r25 }



When our movie stopped to move, we call the function cbFinished(mvK) that initializes everything on the the scene (look at the code above, lines r9-r24).
Its parameter mvK is for button-movie, that should move to destination.
Actually, the only movie mvFA we are using for the moving and do not need this parameter in our example but, it can be useful if we use many button-movies.
The name of destination movie on the scene is mvPoint.

How can we use it?..

To run this example, download files.

You can create a lot of thing using this... We put the button in the randomly flying movie clip just to make management of our example. The function flyAwayRandomly() can be called from out of the flying movie. Also, using the IDesc, you can make your movie appearing from point to its real size.

We created tricky and freaky menu - draft our site map as example how to use this algorithm.
To open item, click on it.
To link, click on the link.
To return back, click on any place except items.
We used the picture of Russian famous artist Konstantin Vasiliev to mage the background nice...








Download Source File

| 1 | 2 | 3 |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

14 users online