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 6845417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:29:53+00:00 2026-05-27T00:29:53+00:00

I am using Flex 4 and AS3 and I am trying to make it

  • 0

I am using Flex 4 and AS3 and I am trying to make it so that the user can draw a freehand line with the cursor – I have this part done.

However, I also need the line to be a dashed line instead of one solid line like it is now. below is my code I am using. I have found some examples on how to do this, but they are all for straight lines, not for a freehand line.

Can anyone help me accomplish this?

Class File (DrawingArea):

package
{
import flash.display.BitmapData;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.utils.ByteArray;

import mx.core.UIComponent;
import mx.events.FlexEvent;
import mx.graphics.codec.PNGEncoder;

public class DrawingArea extends UIComponent
{
    private var isDrawing:Boolean = false;
    private var x1:int;
    private var y1:int;
    private var x2:int;
    private var y2:int;

    public var drawColor:uint = 0x0000FF;

    public function DrawingArea()
    {
        super();

        addEventListener(FlexEvent.CREATION_COMPLETE, function(event:FlexEvent):void {
            graphics.clear();

            graphics.beginFill(0xffffff, 0.00001);
            graphics.drawRect(0, 0, width, height);
            graphics.endFill();
        });

        addEventListener( MouseEvent.MOUSE_DOWN, mouseDown );
        addEventListener( MouseEvent.MOUSE_MOVE, mouseMove );
        addEventListener( MouseEvent.MOUSE_UP, mouseUp);

        function mouseDown(event:MouseEvent):void {
            x1 = mouseX;
            y1 = mouseY;
            isDrawing = true;
        }
        function mouseMove(event:MouseEvent):void {
            if (!event.buttonDown)
            {
                isDrawing = false;
            }

            x2 = mouseX;
            y2 = mouseY;
            if (isDrawing)
            {
                graphics.lineStyle(1, drawColor);
                graphics.moveTo(x1, y1);
                graphics.lineTo(x2, y2);
                x1 = x2;
                y1 = y2;
            }
        }
        function mouseUp(event:MouseEvent):void {
            isDrawing = false;
        }
    }
}
}

Application MXML code:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                         xmlns:s="library://ns.adobe.com/flex/spark" 
                         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<DrawingArea id="drawingArea" xmlns="*" width="100%" height="100%"/>

</s:Application>

Thanks for your help in advance!

  • 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-27T00:29:54+00:00Added an answer on May 27, 2026 at 12:29 am

    public class DrawingArea extends UIComponent
    {
    private var isDrawing:Boolean = false;

    public var drawColor:uint = 0x0000FF;
    
    private var start:Point = new Point;
    private var end:Point = new Point;
    
    public function DrawingArea()
    {
        super();
     }
        addEventListener(FlexEvent.CREATION_COMPLETE, function(event:FlexEvent):void {
            graphics.clear();
    
    
        });
    
        addEventListener( MouseEvent.MOUSE_DOWN, mouseDown );
        addEventListener( MouseEvent.MOUSE_MOVE, mouseMove );
        addEventListener( MouseEvent.MOUSE_UP, mouseUp);
    
        function mouseDown(event:MouseEvent):void {
    
                start = new Point(this.mouseX, this.mouseY);
    
    
        }
        function mouseMove(event:MouseEvent):void {
            grahics.clear();
            end =  new Point(this.mouseX-5, this.mouseY-5);
            graphics.lineStyle(2,0x000000,2);
            drawDashedLine(graphics,start,end,true);
    
        }
        function mouseUp(event:MouseEvent):void {
    
        }
    
    
    
      function drawDashedLine(g:Graphics, start:Point, end:Point, 
                    dashed:Boolean = false, dashLength:Number = 6):void {
            g.moveTo(start.x, start.y);
            if (dashed) {
    
                var total:Number = Point.distance(start, end);
    
                if (total <= dashLength) {
    
                    g.lineTo(end.x, end.y);
                } else {
    
                    var step:Number = dashLength / total;
                    var dashOn:Boolean = false;
                    var p:Point;
                    for (var t:Number = step; t <= 1; t += step) {
                        p = getLinearValue(t, start, end);
                        dashOn = !dashOn;
                        if (dashOn) {
                            g.lineTo(p.x, p.y);
                        } else {
                            g.moveTo(p.x, p.y);
                        }
                    }
    
                    dashOn = !dashOn;
                    if (dashOn && !end.equals(p)) {
                        g.lineTo(end.x, end.y);
                    }
                }
            } else {
    
                g.lineTo(end.x, end.y);
            }
    
    
        }
    

    }

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

Sidebar

Related Questions

Using Flex 3.2, I have a object which extends a TitleWindow. In this TitleWindow
I am trying to make a 'brush' tool in AS3 (pure, not Flex) which
I am using Flex AS3, i have a accordian with two tabs each tab
Is there any way or tool available that can profile AS3 code without using
I have created an API in AS3 that uses Flex bindings. The API is
I've created a linechart in flex using pure as3. I need now to convert
Using Flex 3, I have a Button which is skinned using PNGs specified in
Using Flex 3, I would like to take an image snapshot such as this:
Using Flex and Bison, I have a grammar specification for a boolean query language,
I've created a line chart in Flex using LogAxis. Flex draws minor tick marks

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.