get angle from a circle actionscript? - actionscript-3

I found this answer (Circular Slider in ActionScript 3) which creates a drag-able point over a circle..In the answer there is the code in the CircleSlider class .
private function mouseUpEventHandler(event:MouseEvent):void
{
mThumb.removeEventListener(Event.ENTER_FRAME, enterFrameEventHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpEventHandler);
stage.removeEventListener(Event.MOUSE_LEAVE, mouseUpEventHandler);
trace(mAngle);
}
when i put the trace code it shows the angle when i slide the point on the circle..i want to get that angle to a text box in main script.(frame script).can someone help me?

use text property of your TextField object. Something like this: TEXT_FIELD_NAME.text = String(mAngle);
If you use 1 frame and the textfield obj is into this frame you can use this keyword otherwise you must address right frame/place that contains the textfield object.

Related

moving around the stage(doing a full lap) before ending at a certain point

How do I make that the object that I click, start moving in circles ( 2,3 ) around the stage
before arriving at its end position.Like in this picture
the way I figured out it could be is something like this:
private function onClick( ev:MouseEvent ):void
{
var currentObj:Sprite = ev.currentTarget as Sprite;
TweenLite.to(currentObj, 1, {x:first_X, y:first_Y, onComplete:goToPosition2 });
function goToPosition2():void
{
TweenLite.to(currentObj, 1, {x:secontd_X, y:second_Y, onComplete:goToPosition3 });
}
function goToPosition3():void
{
TweenLite.to(currentObj, 1, {x:third_X, y:third_Y, onComplete:goToPosition4 });
}
..
..
.
.
.
//and so on and so on
}
yet I somehow feel that this is very wrong way of doing it.
A bit interesting, another way of solving it can be to create a movieclip that contains a 'handle' clip inside that follows a motion path. Call this the 'driver clip'.
Then to get a shape/another moiveclip to follow along it, start the driver clip playing at frame 1 and add an event handler. In the event handler, on every frame sync the x and y of the object you want to the driver clip's handle clip inside. Also can set the visibility of that handle clip to false to hide it. When the driver clip reaches the end frame, you can remove the event listener and the shape will be in its finish position.
This method would work for a very irregular shape that would take too long to manually plot in code (assuming you're using the flash ide).
Simple way: contain your object within a parent MovieClip, near its periphery. On click, rotate the parent and also increase its scale, so that your object traces a spiral path.

Changing a information during a tween

I want to change a movieclip.text during a tween.
I got this function, can I change the information on this movieclip when this Tween is happening?
function facaTween(m:MovieClip){
TweenLite.to(m,1,{rotationX:360,ease:Strong.easeInOut});
}
when I tryed this code the as3 changes the information before the tween happens and i want during the tween.
facaTween(hue.obs);
hue.obs.text = "HAHAH";
You can update text in any time, when you want, TweenLite is powerful:
onComplete - change text after tween complete
onStart - change text at start, right before start
Example:
TweenLite.to(m,1,{rotationX:360, onComplete:onFinish, onStart: onBegin, ease:Strong.easeInOut});
function onFinish():void{
hue.obs.text ="Complete";
}
function onBegin():void{
hue.obs.text = "Start";
}
During, you mean with small delay? You can change text a bit after you start tween:
TweenLite.delayedCall(0.2, onSmallDelay);
function onSmallDelay():void{
hue.obs.text = "text after 200ms";
}

In AS3, how can I check to see if mouse is inside a rectangle?

In AS3, how can I check to see if mouse is inside a rectangle after the stage has been clicked in that area?
for example:
var rec:Rectangle = new Rectangle(50, 200, 50, 200);
And the onclick function would do:
if (mouseX <=rec.left && etc...
I've tried many methods, but have still come up empty. Any ideas?
(What I really wanted to do was make an event listener for the rectangle, but it kept throwing errors so I'm trying to figure out a way to do it with an if statement instead.)
This isn't pertinent that I know this, because I can just do this with flat numbers. I'm trying to learn more about rectangles and points. I figured this would work with a rectangle too, but nope.
You can use Rectangles function contains which accepts 2 arguments x and y.
Like this:
var r:Rectangle = new Rectangle(50,200,50,200);
stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
if(r.contains(e.stageX,e.stageY))
{
trace("inside");
}
}

AS3 Determine if MovieClip fills another MovieClip completely

I am trying to determine in AS3 Flash if a draggable movieclip on the stage completely fills another movieclip also on the stage. I looked into another StackOverflow article with this code:
var inter = mcOverlay.getRect(this).intersection(mcLoadedImage.getRect(this));
if ((inter.width * inter.height) == 0) {
return false;
} else {
return true;
}
This code uses the intersect method, it works, but I also want to check that the movieclip is completely covered by the draggable movieclip on the stage.
Any suggestions? Thanks!
I think you could use compare each movieclips rect, ie compare the left, right, top and bottom values.
Instead of using intersection, use Rectangle.contains.
var contains : Boolean = mcContainer.getRect(this).contains(mcContained.getRect(this));
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Rectangle.html#containsRect()

AS3: is it possibile to set the cursor x and y?

is it possibile to set the position of the mouse cursor? This is what I would like to do: when the user presses the mouse button over a movieclip, the movieclip starts dragging and on enterframe the cursor is positioned in the middle of the movieclip (don't tell me about lockcenter because I can't use it this way since my movieclip registration point is set at its top left corner). Basically, I would like to be able to force the cursor to reach the center of the movieclip when the user clicks it. Is this possible?
I don't have proof, but I think that you are not allowed to take control of the cursor like that.
An alternative would be to hide the actual mouse cursor, and add a custom cursor instead that you could positioned relative to the real cursor position, or in the center of your drag target if that would be easier. The problem would be that you have no way of knowing the exact appearance of the user's cursor.
In other words you're looking for this functionality: SetCursorPos.
You cannot control the cursor with Flash. You'll have to solve it otherwise - what about setting your movieclip's registration point to the center?!
I don't think that's possible. The mouse coordinates are read only.
However I would suggest any of these instead :
Hide the mouse using Mouse.hide();.
Make your own pointer in the location of the mouse.
Control this pointer as per your wish.
or
When the mouse button is pressed, move the movieclip itself, if
possible.
Expanding on loxxy's response:
Instead of moving the mouse cursor to the center of the object with lockCenter, you can manually move the object to be centered about the mouse cursor when the MouseEvent.MOUSE_DOWN event is fired on the object (just before you call startDrag on the object)
Here's a simple example:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite{
public function Main() {
var drag_object:Sprite = new Sprite()
drag_object.graphics.beginFill(0xFF0000, .5);
drag_object.graphics.drawRect(0, 0, 50, 50);
drag_object.graphics.endFill();
drag_object.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
drag_object.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
drag_object.x = 200;
drag_object.y = 300;
addChild(drag_object);
}
private function onMouseDown(e:MouseEvent):void {
var obj:Sprite = e.target as Sprite;
obj.x = e.stageX - (obj.width * .5);
obj.y = e.stageY - (obj.height * .5);
obj.startDrag();
}
private function onMouseUp(e:MouseEvent):void {
var obj:Sprite = e.target as Sprite;
obj.stopDrag();
}
}
}