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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:46:49+00:00 2026-06-02T08:46:49+00:00

I was working on a little practice project in AS3 and I ran into

  • 0

I was working on a little practice project in AS3 and I ran into a problem. I’m making a MS Paint style drawing program and I want the user to be able to change the brush size with an input field. I have two issues. The first is that I don’t know how to make an input field through code, and the second is I don’t know how to pass the variable from the input field on the stage to the variable controlling the brush size.

    package  
{
    import flash.display.Sprite;
    import flash.events.MouseEvent; 
    import flash.text.TextField;
    import flash.events.KeyboardEvent;

    public class DrawingApp extends Sprite
    {
        var square0:Sprite;
        var textField: TextField;
        var textField2: TextField;
        var textField3: TextField;
        var square1:Sprite;
        var square2:Sprite;
        var square3:Sprite;
        var lineColor:uint = 0x000000;
        var brushSize:Number = 1;

        public function DrawingApp() 
        {

            square0 = new Sprite();
            addChild(square0);  
            square0.graphics.lineStyle(1,0x000000);
            square0.graphics.beginFill(0x000000);
            square0.graphics.drawRect(0,0,30,20);
            square0.graphics.endFill();
            square0.x = 500;
            square0.y = 10;

            square1 = new Sprite();
            addChild(square1);  
            square1.graphics.lineStyle(1,0x000000);
            square1.graphics.beginFill(0x0000FF);
            square1.graphics.drawRect(0,0,30,20);
            square1.graphics.endFill();
            square1.x = 500;
            square1.y = 40;

            square2 = new Sprite();
            addChild(square2);  
            square2.graphics.lineStyle(1,0x000000);
            square2.graphics.beginFill(0xff0000);
            square2.graphics.drawRect(0,0,30,20);
            square2.graphics.endFill();
            square2.x = 500;
            square2.y = 70;

            textField = new TextField;
            addChild(textField);
            textField.x = 500;
            textField.y = 100;
            textField.width = 30;
            textField.height = 20;
            textField.text = "Eraser";
            textField.selectable = false;  
            textField.border = true; 

            textField2 = new TextField;
            addChild(textField2);
            textField2.x = 500;
            textField2.y = 130;
            textField2.width = 30;
            textField2.height = 20;
            textField2.text = "Clear";
            textField2.selectable = false;  
            textField2.border = true; 

            textField3 = new TextField;
            addChild(textField3);
            textField3.x = 500;
            textField3.y = 160;
            textField3.width = 30;
            textField3.height = 20;
            textField3.text = brushSize;
            textField3.selectable = true;  
            textField3.border = true; 


            init();
        }

        private function init():void
        {
            graphics.lineStyle(1, lineColor, 1);
            square0.addEventListener(MouseEvent.CLICK, changetoDefault);
            square1.addEventListener(MouseEvent.CLICK, changetoBlue);
            square2.addEventListener(MouseEvent.CLICK, changetoRed);
            textField.addEventListener(MouseEvent.CLICK, changetoEraser);
            textField2.addEventListener(MouseEvent.CLICK, clearAll);
            textField3.addEventListener(KeyboardEvent.KEY_DOWN, adjustSize);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseIsDown);
            stage.addEventListener(MouseEvent.MOUSE_UP, mouseIsUp);
        }

        private function changetoEraser(event: MouseEvent):void
        {
            lineColor = 0xffffff;
            graphics.lineStyle(brushSize, lineColor, 1);
        }

        private function adjustSize(event: KeyboardEvent)
        {
            brushSize = textField3.text;
            graphics.lineStyle(brushSize, lineColor, 1);
        }

        private function clearAll(event:MouseEvent):void
        {
            graphics.clear();
            graphics.lineStyle(brushSize, lineColor, 1);
        }

        private function changetoDefault(event: MouseEvent):void
        {
            lineColor = 0x000000;
            graphics.lineStyle(brushSize, lineColor, 1);
        }

        private function changetoBlue(event: MouseEvent):void
        {
            lineColor = 0x0000ff;
            graphics.lineStyle(brushSize, lineColor, 1);
        }

        private function changetoRed(event: MouseEvent):void
        {
            lineColor = 0xff0000;
            graphics.lineStyle(brushSize, lineColor, 1);
        }

        private function mouseIsDown(event: MouseEvent):void
        {
            graphics.moveTo(mouseX, mouseY);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMyMouse);
        }

        private function mouseIsUp(event: MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveMyMouse);
        }

        private function moveMyMouse(event:MouseEvent):void
        {
            graphics.lineTo(mouseX, mouseY);
        }
    }
}

I realized that setting brushSize to textField3.text wouldn’t work because it’s converting string to number. I have no clue how I can make it so that way this works. Thanks to anyone who can shed some light on this for me.

  • 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-06-02T08:46:50+00:00Added an answer on June 2, 2026 at 8:46 am

    You can make an input field from code in Flash by making a TextField and setting its type to TextFieldType.INPUT.

    In order to convert a string to a number you will have to use parseFloat() or parseInt() (I don’t know whether you need an integer or a float by heart).

    Though minimal, I do think this should be enough to help you get you going again.

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

Sidebar

Related Questions

So I'm working on a fun little program and ran across this rather interesting
I'm working on a little program to make my life easier when using Microsoft
I'm working on a little project right now in ActionScript 3. The project is
I'm working on a large-size dual AS3/Flex project (some parts are pure AS3, other
I'm working on a fairly large PHP project written in a procedural style (it
this is more of a 'best practice' question than an actual problem: I'm working
I'm working on a little project to make a 'memeplayer' in Excel with YouTube
Working on a project in AS3 I require to stream a few files for
I've started working a little bit with lift+scala+mongorecord but I found a small annoyance
I'm working on a little Android app to stream some camera footage (as a

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.