Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-03-2012, 07:13 PM   #1
Typo.grapher
Registered User
 
Join Date: Jun 2012
Posts: 5
Default Rotate object on hold and drag

Hi there,
I'm basically trying to do this in as3:

Code:
var pressing:Boolean=false;
var myRadians:Number;
var mydegrees:Number;
bean_mc.onPress=function  () {
	pressing=true;
	spin ();
}
bean_mc.onRelease=bean_mc.onReleaseOutside=function  () {
	pressing=false;
	delete bean_mc.onEnterFrame;
}
function spin () {


bean_mc.onEnterFrame=function  () {
	if (pressing) {
		
		myRadians=Math.atan2((_ymouse-bean_mc._y),(_xmouse-bean_mc._x));
		mydegrees=Math.round(myRadians*180/Math.PI);
		bean_mc._rotation=mydegrees+90;
}

}
}
(This came from a post the user neilmmm answer in 07-16-2007)

I want the user to be able to drag 3 circles around a wheel (one by one). This is what i got so far.

Code:
import flash.events.MouseEvent;

var myRadians:Number;
var myDegrees:Number;

circ1.addEventListener(MouseEvent.MOUSE_DOWN, pressing1);
function pressing1(evt:MouseEvent):void {
	myRadians = Math.atan2((circ1.target.x - this.circ1.x),(circ1.target.y - this.circ1.y));
	myDegrees = Math.round(myRadians*180/Math.PI);
	circ1._rotation = myDegrees;		
};
I couldn't figure out how to change the the circ1._rotation part.

I supose I should just copy the code for the other 2 circles and change the function to pressing2 and pressing3.


PS.: I search the forums but the 3 posts I found on this problem were in as2.
Typo.grapher is offline   Reply With Quote
Old 06-03-2012, 08:10 PM   #2
Typo.grapher
Registered User
 
Join Date: Jun 2012
Posts: 5
Default

I was searching around a bit more and I found this:

Code:
circ1.addEventListener(MouseEvent.MOUSE_DOWN,turn);
stage.addEventListener(MouseEvent.MOUSE_UP,endTurn );

function turn (e:Event):void{
	stage.addEventListener(MouseEvent.MOUSE_MOVE,turn) ;
	var position:Number = Math.atan2(mouseY - circ1.y, mouseX - circ1.x);
	var angle:Number =(position/Math.PI) * 180;
	circ1.rotation = angle;
};

function endTurn(e:MouseEvent):void{
circ1.removeEventListener(MouseEvent.MOUSE_DOWN, turn);
stage.removeEventListener(MouseEvent.MOUSE_MOVE,turn);
circ1.addEventListener(MouseEvent.MOUSE_DOWN,turn);
};
Witch is pretty close to what I want. Except the circle doesn't rotates exactly where it's supose to.

I guess the issue is that it rotates around its registration point and I wish to rotate it around its free transform point. Is that possible?

Last edited by Typo.grapher; 06-03-2012 at 08:22 PM.
Typo.grapher is offline   Reply With Quote
Old 06-03-2012, 11:53 PM   #3
Typo.grapher
Registered User
 
Join Date: Jun 2012
Posts: 5
Default

I finally manage to make it go around the point I wanted by reading about the rotateAroundExternalPoint method.

Code:
import fl.motion.MatrixTransformer

var circ1Mat:Matrix = circ1.transform.matrix;
var circ1Center:Point = new Point((roda.x + roda.width/2),(roda.y + roda.height/2)); 

circ1.addEventListener(MouseEvent.MOUSE_DOWN,turn);
stage.addEventListener(MouseEvent.MOUSE_UP,endTurn );

function turn(e:Event):void {
	stage.addEventListener(MouseEvent.MOUSE_MOVE,turn);
	var position:Number = Math.atan2(mouseY - circ1.y, mouseX - circ1.x);
	var angle:Number = (position / Math.PI) * 180;
	rotateCirc1(angle);
}

function rotateCirc1(angle:Number):void {	
	var mat:Matrix= circ1Mat.clone();			
	MatrixTransformer.rotateAroundExternalPoint(mat, circ1Center.x, circ1Center.y, angle);
	circ1.transform.matrix = mat;	
}

function endTurn(e:MouseEvent):void {
	circ1.removeEventListener(MouseEvent.MOUSE_DOWN, turn);
	stage.removeEventListener(MouseEvent.MOUSE_MOVE,turn);
	circ1.addEventListener(MouseEvent.MOUSE_DOWN,turn);
}
Now the main issue is how to apply this to the other 2 circles. I'm not sure how to solve this.
Typo.grapher is offline   Reply With Quote
Old 06-04-2012, 02:16 AM   #4
Sonny
Senior Member
 
Join Date: Aug 2010
Location: Sydney,Australia
Posts: 132
Default

What is the problem in applying it to the other 2 circles?
Sonny is offline   Reply With Quote
Old 06-06-2012, 05:40 PM   #5
Typo.grapher
Registered User
 
Join Date: Jun 2012
Posts: 5
Default

Hi there,

I'm currently having two problems. When I click the circle it goes backwards about 30 degrees (so my pointer is outset of the circle position, however it stills moves as it suposed to).

The second problem, that I supose it may be solved by figuring out how to move the other 2 circles separatedly is that, when this first circle - that is the smallest - goes behind the other 2 circles I can't click in it again. I'm thinking about a if clause to solve this, but I'm not sure how it would work because I'm new to as3.

Last edited by Typo.grapher; 06-06-2012 at 05:52 PM.
Typo.grapher is offline   Reply With Quote
Old 06-08-2012, 02:08 AM   #6
Typo.grapher
Registered User
 
Join Date: Jun 2012
Posts: 5
Default

I solved the backward movement by adding the original rotation the object had.
Code:
circ1.addEventListener(MouseEvent.MOUSE_DOWN,turn);
stage.addEventListener(MouseEvent.MOUSE_UP,endTurn);

function turn(evt:Event):void {
	stage.addEventListener(MouseEvent.MOUSE_MOVE,turn);
	var position:Number = Math.atan2(mouseY - circ1.y, mouseX - circ1.x);
	var angle:Number = (position / Math.PI) * 180;
	circ1.rotation = angle - 45;
}

function endTurn(evt:MouseEvent):void {
	circ1.removeEventListener(MouseEvent.MOUSE_DOWN,turn);
	stage.removeEventListener(MouseEvent.MOUSE_MOVE,turn);
	circ1.addEventListener(MouseEvent.MOUSE_DOWN,turn);
}
You may close the thread now. Thanks.

Last edited by Typo.grapher; 06-08-2012 at 07:53 PM.
Typo.grapher is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Off

Forum Jump


All times are GMT. The time now is 09:44 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.