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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:07:44+00:00 2026-06-15T01:07:44+00:00

Ok, the idea is simple, set of buttons on the stage, click the button

  • 0

Ok, the idea is simple, set of buttons on the stage, click the button change to color to draw with. I’m trying to learn flash & actionscript and not really sure where my problem is, but I can not figure out how to do this.

package {
import flash.display.Sprite;
import flash.events.MouseEvent;

public class Artist extends Sprite {
    public var drawing:Boolean;
    public var colorArray:Array;
    public var dc;

    public function colors() {
        colorArray = ["0xFF0000","0xFFA500","0xFFFF00","0x00FF00","0x0000FF","0x4B0082","0x8F00FF","0xFF69B4","0x00CCFF","0x008000","0x8B4513"];

        for (var i:int = 0; i < colorArray.length; i++) {
        this["btn_" + i].addEventListener(MouseEvent.CLICK, set_color);
        }
    }

    public function set_color(e:MouseEvent):void {
        dc = colorArray;
    }

    public function Artist() {
        graphics.lineStyle(10,dc);
        drawing = false;
        stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
        stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);
        stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
    }

    public function startDrawing(event:MouseEvent):void {
        graphics.moveTo( mouseX, mouseY);
        drawing = true;
    }

    public function draw(event:MouseEvent) {
        if(drawing) {
            graphics.lineTo(mouseX,mouseY);
        }
    }

    public function stopDrawing(event:MouseEvent) {
        drawing = false;
    }
}

}

  • 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-15T01:07:46+00:00Added an answer on June 15, 2026 at 1:07 am

    You should get the index by the button name, then you can assign the color using the clicked index.

    for (var i:int = 0; i < colorArray.length; i++) {
        this["btn_" + i].addEventListener(MouseEvent.CLICK, set_color);
    }
    
    public function set_color(e:MouseEvent):void {
        // Get the button name and fetch it's index
        var index:int = int(e.currentTarget.name.substring(4));
        dc = colorArray[index];
    }
    

    Also, make sure the colorArray is known throughout the whole class if you want to access it in methods.
    Just define it outside the colors method as Lukasz said:
    protected var colorArray:Array and use numbers not strings for colors 0xFF0000 instead of "0xFF0000"

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

Sidebar

Related Questions

How do you reference a bitmap on the stage in flash using actionscript 3?
The idea is simple. Make a struct for Departments of a store, give it
OK, the idea is simple. Every wordpress site is uses categories and tags taxonomies
So, my idea is quite simple: print all of the possible combinations given X
I'm developing a control which inherits from a System.Windows.Form.Panel. The idea is very simple:
The idea is to write a simple bookmarklet. If the question is a possible
I have no idea how to do this simple task. LightSwitch's Solution Explorer is
a possibly simple problem, but weird why I have no idea how to do
I have a simple task to do using PHP dealing with pagination. The idea
How to use simple TCP/IP sockets connections over/with Net.TCP WCF binding? Idea is –

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.