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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:34:55+00:00 2026-06-14T17:34:55+00:00

Here is the code I have: private function drawRect():Sprite{ var rect:Sprite = new Sprite();

  • 0

Here is the code I have:

private function drawRect():Sprite{
   var rect:Sprite = new Sprite();
   rect.name = "rectName";
   rect.graphics.beginFill(0xffff00);
   rect.graphics.lineStyle(1,0x000000);
   rect.graphics.drawRect(0,0,6,6);
   rect.graphics.endFill();
   rect.addEventListener(MouseEvent.MOUSE_OVER, changeColor);
   rect.addEventListener(MouseEvent.MOUSE_OUT, changeColorBack);
   return rect;
}

private function changeColor(e:MouseEvent):void{
   var newColor:ColorTransform = new ColorTransform();
   newColor.color = 0x00ffff;
   e.target.transform.colorTransform = newColor;
}

private function changeColorBack(e:MouseEvent):void{
   var newColor:ColorTransform = new ColorTransform();
   newColor.color = 0xffff00;
   e.target.transform.colorTransform = newColor;
}

The changeColor and changeColorBack functions work but not how I would like them to. They change the whole color of my Sprite including the line border(stroke) around the rectangle. I want to change just the color inside the rectangle and maintain the rectangle’s border. I don’t see a property in the ColorTransform that allows me to specify the lineStyle so is there a different approach to changing the fill color of my rectagle and maintain the border around it?

  • 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-14T17:34:56+00:00Added an answer on June 14, 2026 at 5:34 pm

    ColorTransform applies to the whole MovieClip regardless of what’s drawn in its graphics property. You could either redraw the rectangle each time you need to:

    import flash.display.Sprite;
    
    function drawRect(target:Sprite, clr:Number):void{
       target.graphics.clear();
       target.graphics.beginFill(clr);
       target.graphics.lineStyle(1,0x000000);
       target.graphics.drawRect(0,0,6,6);
       target.graphics.endFill();
    }
    
    function changeColor(e:MouseEvent):void{
       drawRect(Sprite(e.target), 0x00ffff);
    }
    
    function changeColorBack(e:MouseEvent):void{
       drawRect(Sprite(e.target), 0xffff00);
    }
    
    var rect:Sprite = new Sprite();
    rect.addEventListener(MouseEvent.MOUSE_OVER, changeColor);
    rect.addEventListener(MouseEvent.MOUSE_OUT, changeColorBack);
    this.addChild(rect);
    
    drawRect(rect, 0xffff00);
    

    Or, if you’re set on using ColorTransform for some reason, you could build your outlined rectangle out of two separate Sprites (an outer and an inner) and target the inner Sprite only with the ColorTransform:

    import flash.display.Sprite;
    
    function getRectangle(w:Number, h:Number, x:Number, y:Number, clr:Number):Sprite{
       var sprite:Sprite = new Sprite();
       sprite.name = "rectName";
       sprite.graphics.beginFill(clr);
       sprite.graphics.drawRect(x, y, w, h);
       sprite.graphics.endFill();
    
       return sprite;
    }
    
    function changeColor(e:MouseEvent):void{
       var newColor:ColorTransform = new ColorTransform();
       newColor.color = 0x00ffff;
       inner.transform.colorTransform = newColor;
    }
    
    function changeColorBack(e:MouseEvent):void{
       var newColor:ColorTransform = new ColorTransform();
       newColor.color = 0xffff00;
       inner.transform.colorTransform = newColor;
    }
    
    var rect:Sprite = new Sprite();
    rect.addEventListener(MouseEvent.MOUSE_OVER, changeColor);
    rect.addEventListener(MouseEvent.MOUSE_OUT, changeColorBack);
    this.addChild(rect);
    
    // Outer rectangle for the outline
    var outer:Sprite = getRectangle(8, 8, 0, 0, 0x000000);
    rect.addChild(outer);
    
    // Smaller inner rectangle which can be targeted with the color transform
    var inner:Sprite = getRectangle(6, 6, 1, 1, 0xffff00);
    rect.addChild(inner);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code here: Dim MasterIndex As String()() Private Function Lookup(ByVal Search_path As
Here's the c# code that I have: private double get806Fees (Loan loan) { Loan.Fee.Items
Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= cmd.exe commandsBuffer ::=
I am having problems accessing sub-children of my displayObject. Here is my code:private function
I have this code: package graphics { import flash.display.Sprite; import flash.events.*; public class Ball
Here is the code I have written for Rectangle class. class Rectangle (l: Double,
enter code here I have a table on SQL server 2005 with bigint primary
Here is the code I have to create an UIAlertView with a textbox. UIAlertView
Here's the code I have: from cStringIO import StringIO from lxml import etree xml
enter code here I have a ListView that have a different Layout XML for

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.