Flash CS3

Free tutorials and scripts for all

Sometimes members don't get their activation email.
This happens because it gets deleted by accident, your spam folder gets it ... lots of reasons.
To Resend the account activation code you need to do two things:
1. Go here: Resend your activation email
2. Enter the email address you used when you signed up and click "Email activation codes"
3. When the email arrives in your inbox, be sure to click the link to activate your account.

StartDrag with Flash CS3 - Actionscript 3.0

This is a discussion on StartDrag with Flash CS3 - Actionscript 3.0 within the Tutorials forums, part of the English Forums category; Here is another small change that happened from Actionscript 2.0 to Actionscript 3.0 . The method startDrag of the ...


Go Back   Forum Flash CS3 > English Forums > Tutorials

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  4 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 09-10-07, 18:27
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,319
Blog Entries: 1
Rep Power: 6
Flep is on a distinguished road
StartDrag with Flash CS3 - Actionscript 3.0

Here is another small change that happened from Actionscript 2.0 to Actionscript 3.0 .
The method startDrag of the MovieClip class has been ( in my opinion ) significantly improved without major changes.
Here are those changes?
Within Actionscript 2.0, you could control the drag of a MovieClip using, in fact, startDrag with its 5 parameters :
lock center: true or false, specifies if, while dragging the MovieClip, its centre corresponds to the Mouse centre ( true ) or the point where the click happened ( false ).
left: leftmost drag point
top: uppermost drag point
right: rightmost drag point
bottom: lowermost drag point

Within Actionscript 3.0, the drag is controlled by passing an instance of the Rectangle class to the startDrag method, which now accepts only 2 parameters:
lock center: as in Actionscript 2.0
bounds: Rectangle class instance

In order to use the bounds parameter, it?s sufficient to create a virtual rectangle remembering that only 4 simple parameters are needed to create a Rectangle object:

x: the x coordinate where the rectangle begins
y: the y coordinate where the rectangle begins
width: the width of the rectangle
height: its height

So, as you can see in the class I?ve written:
Code:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	public class Controllo extends MovieClip
	{
		private var rect:Rectangle;
		
		public function Controllo()
		{
			init();
		}
		
		private function init():void
		{
			stage.frameRate=31;
			
			ball_mc.x=sfondo_mc.x;
			ball_mc.y=sfondo_mc.y;
			ball_mc.buttonMode=true;
			
			initRectangle();
			initListener();
		}
		
		private function initRectangle():void
		{
			rect=new Rectangle(sfondo_mc.x-sfondo_mc.width/2+ball_mc.width/2,
							   sfondo_mc.y-sfondo_mc.height/2+ball_mc.height/2,
							   sfondo_mc.width-ball_mc.width,
							   sfondo_mc.height-ball_mc.height);
		}
		
		private function initListener():void
		{
			ball_mc.addEventListener(MouseEvent.MOUSE_DOWN,iniziaDrag);
			stage.addEventListener(MouseEvent.MOUSE_UP,stoppaDrag);
		}
		
		private function iniziaDrag(e:MouseEvent):void
		{
			ball_mc.startDrag(false,rect);
		}
		private function stoppaDrag(e:MouseEvent):void
		{
			ball_mc.stopDrag();
		}
	}
}
The result:







In this case, instead of creating a sort of virtual rectangle with new coordinates, I?ve passed the coordinates of sfondo_mc to the startDrag method.

Stay tuned !
__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !
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
StartDrag multiplo lorenzz Flash CS3 generale 5 08-02-08 21:36
Attach image from library with Flash CS3 and Actionscript 3.0 Flep Tutorials 0 09-10-07 18:14
startDrag() StefanoV Actionscript 3.0 avanzato 2 06-10-07 18:25
startDrag controllato con Flash CS3 Flep Articoli e tutorials 0 19-09-07 13:31
E' arrivato Flash CS3 - appoggiato da Actionscript 3.0 Flep Articoli e tutorials 0 19-09-07 10:15


All times are GMT. The time now is 19:20.


Powered by vBulletin versione 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap

FlepStudio
by Filippo Lughi
P.IVA 03605860406