Hello guys, i'll go straight to the point here.
I have some rectangulars one on top of each other and a list of colors next to them. I want the user to click a rectangular then select a color.
Hello guys, i'll go straight to the point here.
I have some rectangulars one on top of each other and a list of colors next to them. I want the user to click a rectangular then select a color.
Short, practical recap (for anyone finding this thread later): had stacked rectangle movieclips and wanted to click one, then pick a color to apply. pointed to AS2/AS3 color docs and the OP solved it. Below is a compact, reliable pattern you can reuse and a few common gotchas.
AS3: attach a click listener to each rectangle, store the clicked clip (use event.currentTarget), then apply a ColorTransform. This replaces the clip tint cleanly.
import flash.geom.ColorTransform;
var selectedClip:MovieClip;
function onRectClick(e:MouseEvent):void {
selectedClip = e.currentTarget as MovieClip;
}
function applyColor(hex:uint):void {
if (!selectedClip) return;
var ct:ColorTransform = selectedClip.transform.colorTransform;
ct.color = hex;
selectedClip.transform.colorTransform = ct;
} AS2: same idea but use the Color object.
var selectedClip:MovieClip;
function onRectClick():Void {
selectedClip = this;
}
function applyColor(hex:Number):Void {
if (!selectedClip) return;
var c:Color = new Color(selectedClip);
c.setRGB(hex);
} Troubleshooting and tips: a plain stage Shape cannot be referenced at runtime—convert it to a MovieClip instance. event.target can be a nested child; use currentTarget when you want the clip that had the listener. colorTransform affects the whole clip (and children); if you need to recolor only a specific part, give that part its own instance name and target it. Save the original colorTransform if you want to revert. Finally, note that Flash Player was officially discontinued in 2020, so for new projects prefer HTML5/Canvas workflows or export options in Adobe Animate.
Jump to Post— Member #334542Please follow the instruction in the given link:
AS2.0:
http://www.kirupa.com/developer/actionscript/color.htm
Please follow the instruction in the given link:
AS2.0:
http://www.kirupa.com/developer/actionscript/color.htm
thanks i have solved it
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.