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 3 of 3

Thread: Math proportions

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

    Math proportions

    flash templates
    Augh!
    Flash and Actionscript developing requires some Math tips often.It's useful to give best result at our animations and lift up the user interactivity.
    In this sample i want keep the attraction son the Math proportions applied in Actionscript 3.0.
    As we know, the proportion law is:
    x:10=2:20
    and we can get the x value by using inverse formulas.
    By replacing the the formula's values with the MovieClip properties we need in our application, we get this:








    The Class i have wrote is the following:
    Code:
    package
    {
    	import flash.display.MovieClip;
    	import flash.events.*;
    	import flash.geom.Rectangle;
    	
    	public class Balance extends MovieClip
    	{
    		private var offSet:Number;
    		private var start_1:Number;
    		private var start_2:Number;
    		
    		private var my_rect:Rectangle;
    		
    		public function Balance()
    		{
    			init();
    		}
    		
    		public function init():void
    		{
    			stage.frameRate=31;
    			
    			//handler_mc.buttonMode=true;
    			handler_mc.useHandCursor=true;
    			bg_mc.x=handler_mc.x;
    			bg_mc.y=handler_mc.y;
    			handler2_mc.x=bg2_mc.x;
    			handler2_mc.y=bg2_mc.y;
    			handler3_mc.x=bg3_mc.x;
    			handler3_mc.y=bg3_mc.y;
    			
    			offSet=bg_mc.height-handler_mc.height;
    			start_1=handler2_mc.x;
    			start_2=handler3_mc.x;
    			my_rect=new Rectangle(bg_mc.x,bg_mc.y,0,offSet);
    			
    			initEvents();
    		}
    		
    		public function initEvents():void
    		{
    			handler_mc.addEventListener(MouseEvent.MOUSE_DOWN,mouseIsDown);
    			stage.addEventListener(MouseEvent.MOUSE_UP,mouseIsUp);
    		}
    		public function mouseIsDown(event:Event):void
    		{
    			handler_mc.startDrag(false,my_rect);
    			handler_mc.addEventListener(Event.ENTER_FRAME,applyBalance);
    		}
    		public function mouseIsUp(event:Event):void
    		{
    			handler_mc.stopDrag();
    			handler_mc.removeEventListener(Event.ENTER_FRAME,applyBalance);
    		}
    		public function applyBalance(event:Event):void
    		{
    			
    			var p:Number=handler_mc.y-bg_mc.y;
    			var percentage:Number=Math.ceil((p/offSet)*100);
    			
    			handler2_mc.x=start_1+(percentage/100)*(bg2_mc.width-handler2_mc.width);
    			handler3_mc.x=start_2+(percentage/100)*(bg3_mc.width-handler3_mc.width);
    			circle_mc.rotation=(percentage/100)*360;
    		}
    	}
    }
    Have fun!

  2. #2
    Junior Member Settled In blueman is on a distinguished road
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    Re: Math proportions

    This doesn't help very much if we do not have the _mc's you have in your library. Is the FLA downloadable?

  3. #3
    Junior Member Settled In blueman is on a distinguished road
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    Re: Math proportions

    Nevermind, it was simple to reconstruct.

+ Reply to Thread

Similar Threads

  1. Math question
    By nosrevlah08 in forum advanced Actionscript 3.0
    Replies: 1
    Last Post: 31-03-09, 18:46
  2. Limit the range of Colors using Math.random()
    By Magdy in forum advanced Actionscript 3.0
    Replies: 0
    Last Post: 15-05-08, 19:48
  3. best size stage proportions?
    By donteatyourfriends in forum Actionscript 3.0 newbies
    Replies: 0
    Last Post: 02-04-08, 06:52

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