Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 10 of 10

Thread: effect - Fallen leaves

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    effect - Fallen leaves

    flash templates
    Good morning!

    Here is a new tutorial about animation realised with Flash CS3.
    After having seen how to simulate water and clouds , we will next see how to realise the effect of fallen leaves. Those leaves could be replaced with any other shape you fancy.
    I am not a graphic person so let your fantasy runs wild.
    The script"

    I create a FLA and I save it as "main.fla".
    In its library, I have 6 different MovieClip, each one of them associated to a class and so, ready to be "attached" at runtime.
    The names of the class are: mc_clip_0,mc_clip_1,mc_clip_2,mc_clip_3,mc_clip_4, mc_clip_5.
    Even more, I have a MovieClip on stage used as background (a simple image in my case) with an instance name "bg_mc".

    I create the Documents Class, an AS file saved as "Main.as", implemented the following way:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.utils.Timer;
    	import flash.events.Event;
    	import flash.events.TimerEvent;
    	
    	public class Main extends MovieClip
    	{
    		private var clips_array:Array;
    		
    		private const SPRING:Number=.1;
    		
    		private var timer:Timer;
    		
    		public function Main()
    		{
    			init();
    			initTimer();
    		}
    		
    		private function init():void
    		{
    			stage.frameRate=31;
    			
    			bg_mc.x=0;
    			bg_mc.y=0;
    			bg_mc.width=stage.stageWidth;
    			bg_mc.height=stage.stageHeight;
    			
    			clips_array=new Array(mc_clip_0,mc_clip_1,mc_clip_2,mc_clip_3,mc_clip_4,mc_clip_5);
    		}
    		
    		private function initTimer():void
    		{
    			timer=new Timer(250,0);
    			timer.addEventListener(TimerEvent.TIMER,go);
    			timer.start();
    		}
    		
    		private function go(evt:TimerEvent):void
    		{
    			var n:Number=Math.floor(Math.random()*clips_array.length);
    			var clip:MovieClip=new clips_array[n];
    			
    			clip.x=Math.random()*stage.stageWidth;
    			clip.y=-clip.height;
    			clip.center=clip.x;
    			clip.vel_x=2+Math.random()*10;
    			clip.vel_y=clip.vel_x;
    			clip.angle=0;
    			addChild(clip);
    			
    			clip.addEventListener(Event.ENTER_FRAME,goDown);
    		}
    		
    		private function goDown(evt:Event):void
    		{
    			var acc_x:Number=(evt.target.center-evt.target.x)*SPRING;
    			evt.target.vel_x+=acc_x;
    			evt.target.x+=evt.target.vel_x;
    			evt.target.y+=15-evt.target.vel_y;
    			evt.target.rotation++;
    			var sine:Number=Math.sin(evt.target.angle);
    			evt.target.scaleX=sine;
    			evt.target.angle+=.1;
    			if(evt.target.y>=stage.stageHeight+100)
    			{
    				evt.target.removeEventListener(Event.ENTER_FRAME,goDown);
    				var m:MovieClip=evt.target as MovieClip;
    				removeChild(m);
    			}
    		}
    	}
    }
    The result:






    Let us analyse the code:
    Properties
    an Array into which I insert the name of the class associated to the MovieClips placed in library
    var clips_array:Array;
    a numerical constant which would be the spring seen in the spring or Spring and Friction or Spring and Mouse
    private const SPRING:Number=.1;
    a Timer
    private var timer:Timer;

    Consctructor function
    I call the method init
    init();
    I call the method initTimer
    initTimer();

    Methods
    init();
    I impost the frame rate
    stage.frameRate=31;
    I tell the background image to keep to x and y equal zero. If wanted I could view the SWF at 100% as I will also tell that the width and length of bg_mc is equal to the stage size
    bg_mc.x=0;
    bg_mc.y=0;
    bg_mc.width=stage.stageWidth;
    bg_mc.height=stage.stageHeight;
    I initialise the Array
    clips_array=new Array(mc_clip_0,mc_clip_1,mc_clip_2,mc_clip_3,mc_c lip_4,mc_clip_5);

    initTimer();
    I create a new Timer and impost it to a speed of 250 for an unlimited time
    timer=new Timer(250,0);
    I add a listener to the Timer which will call the method go every 250 milliseconds
    timer.addEventListener(TimerEvent.TIMER,go);
    I start the Timer
    timer.start();

    go();
    I create a numerical variable with a random value starting from 0 to 5 so to cover the full length of the Array
    var n:Number=Math.floor(Math.random()*clips_array.leng th);
    I attach the MovieClip from the library.
    NB: nes clips_array[n]; Flash looks into the index n of the Array and finds out that there is a class associated to it, so it does nothing else then attach that MovieClip
    var clip:MovieClip=new clips_array[n];
    I impost a x and y to clip
    clip.x=Math.random()*stage.stageWidth;
    clip.y=-clip.height;
    I create 4 properties to clip needed for the animation
    clip.center=clip.x;
    clip.vel_x=2+Math.random()*10;
    clip.vel_y=clip.vel_x;
    clip.angle=0;
    I add clip to the stage
    addChild(clip);
    I create an ENTER_FRAME that acts on the clip and calls the method goDown
    clip.addEventListener(Event.ENTER_FRAME,goDown);

    goDown();
    I apply the spring effect to the coordinates x of clip
    var acc_x:Number=(evt.target.center-evt.target.x)*SPRING;
    evt.target.vel_x+=acc_x;
    evt.target.x+=evt.target.vel_x;
    I increase the coordinate y
    evt.target.y+=15-evt.target.vel_y;
    I rotate the clip
    evt.target.rotation++;
    I create a variable to which I assign the value of the angle"s sinus (retrieved from the property angle of the clip itself)
    var sine:Number=Math.sin(evt.target.angle);
    I assign the value of the sinus to the property scaleX of clip
    evt.target.scaleX=sine;
    I increase the property angle of clip
    evt.target.angle+=.1;
    I check clip y. If it is bigger then the stage plus 100
    if(evt.target.y>=stage.stageHeight+100)
    {
    I stop the ENTER_FRAME associated to that clip
    evt.target.removeEventListener(Event.ENTER_FRAME,g oDown);
    I remove clip
    var m:MovieClip=evt.target as MovieClip;
    removeChild(m);
    }

    Stay tuned !

  2. #2
    Member Flash Addict gwulfwud is on a distinguished road
    Join Date
    Nov 2007
    Posts
    59
    Rep Power
    3

    Re: effect ? Fallen leaves

    hey flep...where can i find that water and cloud simulation? i can't find it with the search button..

    =D

  3. #3
    Member Flash Addict hard_overclocker is on a distinguished road hard_overclocker's Avatar
    Join Date
    Jul 2007
    Posts
    50
    Rep Power
    4

    Re: effect ? Fallen leaves


  4. #4
    Member Flash Addict gwulfwud is on a distinguished road
    Join Date
    Nov 2007
    Posts
    59
    Rep Power
    3

    Re: effect ? Fallen leaves

    thank you!!!

  5. #5
    Junior Member Settled In advitum is on a distinguished road
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Re: effect ? Fallen leaves

    Can you post the .FLA for Fallen Leaves in the Downloads area?

  6. #6
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Re: effect ? Fallen leaves

    Hi advitum,
    you can download it here:

    http://www.flepstudio.org/sharing/fallen_leaves.zip

  7. #7
    Newbie Settled In sbrown80 is on a distinguished road
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Re: effect ? Fallen leaves

    Tried the leaves tutorial, can't seem to get it to work. Having issues with the flash portion of the file talking about creating document classes for each of the movie clips which I did. Named the main timeline 'main' and the document class for the doc 'main' as well. Each of the movie clips are named, 'mc_clip_0...' and their doc class is named 'mc_clip_0...' .
    When SWF file is created, nothing shows up.

    Any help would be greatly appreciated!
    SB-

  8. #8
    Junior Member Settled In advitum is on a distinguished road
    Join Date
    Jan 2008
    Posts
    2
    Rep Power
    0

    Re: effect ? Fallen leaves

    Thank you kindly, Flep. Adding Trace statements to the code has been helpful to understand the tutorial.

  9. #9
    Junior Member Settled In aspiringpro is on a distinguished road
    Join Date
    Jun 2009
    Posts
    1
    Rep Power
    0

    Re: effect - Fallen leaves

    How would you place this code inside of a pre-existing movie?

  10. #10
    Junior Member Settled In luxoid is on a distinguished road
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Re: effect - Fallen leaves

    Hello all! Nice tutorial!

    Flep I like to ask you how can I place the whole Class into a layer, or mc?
    I like to make a money falling animation in a hourglass.
    I've already modified the AS to make a smooth animation for money falling from one point but I like to place a a sand growing animation above the money. How can I control layers with classes or how can I put layers above the falling animation?
    The imported animation is above all of the existing layers.
    Please help me! It's really important!

    Thank you!
    LuX

+ Reply to Thread

Similar Threads

  1. Eraser effect
    By Flep in forum Flash CS4 Tutorials
    Replies: 4
    Last Post: 25-05-10, 13:09
  2. FishEye effect
    By Flep in forum Tutorials
    Replies: 0
    Last Post: 23-02-10, 12:40
  3. Writing Pen Effect
    By lucifier27 in forum Flash English
    Replies: 0
    Last Post: 28-09-09, 03:24
  4. 10 Effect XML Menu
    By info@amicidelvolo.it in forum Componenti
    Replies: 13
    Last Post: 19-09-09, 06:55
  5. Smoke effect AS2 to AS3
    By varatojo in forum Actionscript 3.0 newbies
    Replies: 0
    Last Post: 16-02-09, 00:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts