Skip to main content
chienbleu
Known Participant
July 11, 2022
Answered

please help. i have no idea what i'm doing

  • July 11, 2022
  • 2 replies
  • 331 views

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();
}
}

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    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

    2 replies

    Community Expert
    July 13, 2022

    code snippets can be your best friend.

    JoãoCésar17023019
    Community Expert
    Community Expert
    July 11, 2022

    Hi.

     

    Are you coding in a frame or a class file?

    chienbleu
    chienbleuAuthor
    Known Participant
    July 11, 2022

    frame. also "export to actionscript" is off

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    July 11, 2022

    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