Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Math proportions

This is a discussion on Math proportions within the Tutorials forums, part of the Flash English category; Augh! Flash and Actionscript developing requires some Math tips often.It's useful to give best result at our animations ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-10-07, 17:21
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Math proportions

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!
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 15-04-08, 04:27
Junior Member
 
Join Date: Feb 2008
Posts: 2
Rep Power: 0
blueman is on a distinguished road
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 15-04-08, 06:00
Junior Member
 
Join Date: Feb 2008
Posts: 2
Rep Power: 0
blueman is on a distinguished road
Re: Math proportions

Nevermind, it was simple to reconstruct.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 3 Math question nosrevlah08 advanced Actionscript 3.0 0 21-08-08 23:10
Limit the range of Colors using Math.random() Magdy advanced Actionscript 3.0 0 15-05-08 20:48
best size stage proportions? donteatyourfriends Actionscript 3.0 newbies 0 02-04-08 07:52


All times are GMT. The time now is 16:31.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap