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

  • Home
  • SEARCH
  • 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 9185179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:13:38+00:00 2026-06-17T19:13:38+00:00

I have the following class, that represents a red circle: public class AElement extends

  • 0

I have the following class, that represents a red circle:

public class AElement extends UIComponent {

    public var radius:int;

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
        graphics.beginFill(0xFF0000);
        graphics.drawCircle(x, y, radius);
        graphics.endFill();
    }

}

I would like to add a method that changes the color of the circle, so I came up with this solution:

    public function updateColor(color:uint):void {
        graphics.beginFill(color);
        graphics.drawCircle(x, y, radius);
        graphics.endFill();
    }

It works, but I believe this only draws another circle on top of the first one.

Is there any way to change the first circle’s color instead of drawing another one ?

  • 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-17T19:13:38+00:00Added an answer on June 17, 2026 at 7:13 pm

    Just call .clear() before you start drawing

    public function updateColor(color:uint):void {
        graphics.clear();
        graphics.beginFill(color);
        graphics.drawCircle(x, y, radius);
        graphics.endFill();
    }
    

    then you can redraw in a new colour.

    Edit:

    To change the colour of an object you can use ColorTransform:

    myDisplayObject.transform.colorTransform = new ColorTransform(0, 0, 0, 0, r, g, b, a);
    

    Where r,g and b are the red,green and blue parts of the colour, and a is the alpha value (all between 0-255). eg:

    public function updateColor(color:uint):void {
        var a:int = (color&0xFF000000)>>24;
        var r:int = (color&0x00FF0000)>>16;
        var g:int = (color&0x0000FF00)>>8;
        var b:int = (color&0x000000FF);
        this.transform.colorTransform = new ColorTransform(0, 0, 0, 0, r, g, b, a);
    }
    

    or for colours without alpha:

    public function updateColor(color:uint):void {
        var r:int = (color&0xFF0000)>>16;
        var g:int = (color&0x00FF00)>>8;
        var b:int = (color&0x0000FF);
        this.transform.colorTransform = new ColorTransform(0, 0, 0, 0, r, g, b, 255);
    }
    

    However, this affects the whole display object and any children – not just whatever is drawn to graphics. So, assuming your class contains other visual objects, you’d be better sticking with the clear() option (imho).

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

Sidebar

Related Questions

I have a class that looks like the following: public class MyClass { private
We have a class a class that looks something like the following: public class
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
I have the following test class that represents a composite _id: private sealed class
I have a Model similar to the following public class TaskModel { public int
I have the following class written by someone else that I'm trying to understand
I have the following methods in my Authentication class that is called by my
I have the following ugly if statement that is part of a class that
Assume that we have the following code: class Program { static volatile bool flag1;
I have a class that has the following property that is generated by the

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.