Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:58+00:00 2026-05-26T12:12:58+00:00

I am trying to create a Flash application which will allow a user to

  • 0

I am trying to create a Flash application which will allow a user to draw arrows on the screen/canvas by using the mouse. So if they click and hold the left mouse button at coordinates 23,12 and release the left button at 84,45 a line would be drawn between the 2 points with an arrow head at the second coordinate.

I also need each individual arrow to be selectable so they can be moved or deleted (I know how to do this part!).

If someone could help me and point me in the right direction (such as an example or tutorial), it would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:12:58+00:00Added an answer on May 26, 2026 at 12:12 pm

    Since it’s your first question:

    enter image description here

    package
    {
        import flash.display.CapsStyle;
        import flash.display.Graphics;
        import flash.display.JointStyle;
        import flash.display.LineScaleMode;
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.geom.Point;
    
        [SWF(percentWidth = 100, percentHeight = 100, backgroundColor = 0xefefef, frameRate = 30)]
        public class Arrows extends Sprite
        {
    
            public var arrows:Vector.<Sprite> = new Vector.<Sprite>();
    
            public var canvas:Sprite;
    
            public var lineColor:uint = Math.random() * 0xffffff;
    
            public var lineWeight:Number = 5;
    
            private var startPoint:Point;
    
    
            public function Arrows()
            {
                super();
    
                addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
            }
    
            protected function addedToStageHandler(event:Event):void
            {
                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.align = StageAlign.TOP_LEFT;
    
                addCanvas();
            }
    
            protected function addCanvas():void
            {
                canvas = new Sprite();
                addChild(canvas);
    
                lineColor = Math.random() * 0xffffff;
    
                // give alpha for interaction
                var g:Graphics = canvas.graphics;
                g.beginFill(0x0, 0.0);
                g.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
                g.endFill();
    
                // listen for mouse down
                canvas.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            }
    
            protected function mouseDownHandler(event:MouseEvent):void
            {
                canvas.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    
                // mark start point
                startPoint = new Point(event.localX, event.localY);
    
                // start rendering
                canvas.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    
                // listen for mouse up / out to end arrow
                canvas.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
                canvas.addEventListener(MouseEvent.MOUSE_OUT, mouseUpHandler);
            }
    
            protected function enterFrameHandler(event:Event):void
            {
                var angle:Number = polarAngle(new Point(mouseX, mouseY), new Point(startPoint.x, startPoint.y));
    
                // draw line
                var g:Graphics = canvas.graphics;
                g.clear();
    
                // give alpha for interaction
                g.beginFill(0x0, 0.0);
                g.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
                g.endFill();
    
                g.lineStyle(lineWeight, lineColor, 1, true, LineScaleMode.NORMAL, CapsStyle.SQUARE, JointStyle.MITER);
                g.moveTo(startPoint.x, startPoint.y);
                g.lineTo(mouseX, mouseY);
    
                // draw arrow head
                g.moveTo(mouseX - (20 * Math.cos((angle - 45) * Math.PI / 180)),
                         mouseY - (20 * Math.sin((angle - 45) * Math.PI / 180)));
    
                g.lineTo(mouseX + (5 * Math.cos((angle) * Math.PI / 180)),
                         mouseY + (5 * Math.sin((angle) * Math.PI / 180)));
    
                g.lineTo(mouseX - (20 * Math.cos((angle + 45) * Math.PI / 180)),
                         mouseY - (20 * Math.sin((angle + 45) * Math.PI / 180)));
            }
    
            protected function polarAngle(point:Point, center:Point=null):Number
            {
                if (!center)
                    center = new Point(0, 0);
    
                return Math.atan2(point.y - center.y, point.x - center.x) * 180 / Math.PI;
            }
    
            protected function mouseUpHandler(event:MouseEvent):void
            {
                canvas.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
                canvas.removeEventListener(MouseEvent.MOUSE_OUT, mouseUpHandler);
    
                // stop rendering
                canvas.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
    
                // push canvas to arrows collection
                arrows.push(canvas);
    
                // add a fresh canvas
                addCanvas();
            }
    
        }
    }
    

    You say you know how to move them, so I’ll leave that up to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to create an application in flash builder 4.5.1 and try to
Using Flash Builder 4 (with 4.1 flex). Trying to create a state change after
I'm using Flash builder, with flex 4 sdk and am trying to create a
I'm trying to create a datagrid which will resize vertically to ensure all the
I'm trying to create a ruby on rails ecommerce application, where potential customers will
I'm trying to create a facebook application that is flash (actually flex 4.1) based.
I'm very new to Flash Builder and am trying to create an AIR app
Ok so I am trying create a login script, here I am using PHP5
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.