Copy link to clipboard
Copied
I've been trying to make something point in another things direction but it's saying unexpected packages then it's saying public funtion is only allowed in a package then access of undefined property then left paren before left brace and so on. here is the code. currently there it's not saying where or what the error is so just take a look:
import flash.display;
import flash.events;
class rHit extends MovieClip
{
rHit.addEventListener(Rat);
function Rat();
{
var angle:Number = Math.atan2 (r.Y, r.X);
var degrees:Number = angle * 180/Math.PI;
rHit.rotation = degrees;
trace();
}
}
Hi.
Are you coding in a frame or a class file?
Got it.
So don't use class or package keywords/structure because they are reserved for class files.
I don't know exactly what you were trying to achieve, so I coded a generic "rotate to target" example.
AS3 code:
import flash.events.Event;
import flash.events.MouseEvent;
function enterFrameHandler(e:Event):void
{
var angle: Number = Math.atan2(target.y - arrow.y, target.x - arrow.x);
var degrees: Number = angle * 180 / Math.PI;
arrow.rotation = degrees;
}
function mouseDownHandler(e
...
Copy link to clipboard
Copied
Hi.
Are you coding in a frame or a class file?
Copy link to clipboard
Copied
frame. also "export to actionscript" is off
Copy link to clipboard
Copied
Got it.
So don't use class or package keywords/structure because they are reserved for class files.
I don't know exactly what you were trying to achieve, so I coded a generic "rotate to target" example.
AS3 code:
import flash.events.Event;
import flash.events.MouseEvent;
function enterFrameHandler(e:Event):void
{
var angle: Number = Math.atan2(target.y - arrow.y, target.x - arrow.x);
var degrees: Number = angle * 180 / Math.PI;
arrow.rotation = degrees;
}
function mouseDownHandler(e:MouseEvent):void
{
arrow.startDrag();
}
function mouseUpHandler(e:MouseEvent):void
{
stopDrag();
}
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
Please notice that the arrow artwork must be facing to the right because that's the 0 degree in Flash/AS3.
FLA / source / code / files:
https://github.com/joao-cesar/adobe/tree/master/animate%20cc/as3/rotate_instance_to_target
Regards,
JC
Copy link to clipboard
Copied
Thank you so much, João! this is exactly what i wanted. this helps so much
-soft sheep
Copy link to clipboard
Copied
You´re welcome!
Copy link to clipboard
Copied
code snippets can be your best friend.