在 Flash CS4 AS3.0 中,如何通过单击更改形状填充颜色?

发布于 2024-11-15 08:39:02 字数 145 浏览 3 评论 0原文

我正在为年幼的孩子建立一个活动,他们点击调色板中的颜色(鼠标光标将是画笔),然后点击我将分层创建图片的各种形状。

根据他们选择的颜色,他们应该能够用该颜色填充形状。中途改变颜色改变主意等。

如果更容易的话,使用早期的 AS 版本我没有任何问题。

I'm building an activity for young kids where they click on a colour in a palette (mouse cursor will be a paint brush) then click on various shapes that I'll layer to create a picture.

depending on the colour they select they should be able to fill the shapes with that colour. Change colors half way through change their mind etc.

I have no issues using an earlier AS version if its easier.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世界等同你 2024-11-22 08:39:02

您可以使用 flash.filters.ColorMatrixFilter - 链接文档中有示例。

使用 Tweener 的 ColorShortcuts 通过分配 < code>_Color 属性是一个十六进制颜色值。此外,此方法还可以让您通过选择为所需的 time 属性分配一个非零值来轻松淡入颜色。

Tweener.addTween(myShape, {time: 0.0, _Color: 0xFF0000});

请记住,任何位图过滤器(例如阴影)或形状的任何子项(如果它是精灵)也会改变颜色。尽管使用容器来分离形状的每个元素也同样容易。


[编辑] 您可以使用 ColorTransform 对象可轻松更改显示对象的颜色。这也是AS3中最常见的做法。这是一个示例:

import flash.geom.ColorTransform;

var myShape:Shape = new Shape();
myShape.graphics.beginFill(0xFF0000, 1.0);
myShape.graphics.drawRect(0, 0, 100, 100);
myShape.graphics.endFill();

addChild(myShape);

var myColorTransform:ColorTransform = new ColorTransform;
myColorTransform.color = 0x0000FF;
myShape.transform.colorTransform = myColorTransform;

上面的代码绘制了一个红色矩形,将其添加到舞台上,然后使用 ColorTransform 对象将其颜色更改为蓝色。

you can use flash.filters.ColorMatrixFilter - there are examples in the linked documentation.

it's also very easy to do this using Tweener's ColorShortcuts by assigning the _Color property a hexidecimal color value. this method additionally lets you very easily fade in the color by optionally assigning a non-zero value to the required time property.

Tweener.addTween(myShape, {time: 0.0, _Color: 0xFF0000});

keep in mind that any bitmap filters, like drop shadows, or any children of your shape (if it's a sprite) will also change color. although it's just as easy to separate each element of your shape by using a container.


[EDIT] rather than using Tweener, as i hastily suggested earlier, or the rather complicated ColorMatrixFilter, you can use a ColorTransform object to easily change the color of a display object. this is also the most common approach in AS3. here's an example:

import flash.geom.ColorTransform;

var myShape:Shape = new Shape();
myShape.graphics.beginFill(0xFF0000, 1.0);
myShape.graphics.drawRect(0, 0, 100, 100);
myShape.graphics.endFill();

addChild(myShape);

var myColorTransform:ColorTransform = new ColorTransform;
myColorTransform.color = 0x0000FF;
myShape.transform.colorTransform = myColorTransform;

the above code draws a red rect, adds it to the stage and then uses a ColorTransform object to change its color to blue.

小女人ら 2024-11-22 08:39:02

我必须警告您,要使其像 Paint 那样工作实际上非常困难。

我会考虑将整个画布设为位图

资源:

  1. 位图
  2. < a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html" rel="nofollow">BitmapData(这个有关键方法)

当绘制形状等时,使用 fillRect() 方法。对于像油漆桶这样的工具(如油漆),请查看 floodFill() 方法。

我不太确定如何创建一个油漆桶工具,但我的想法是沿着使用 getPixel() 查看单击位置周围每个像素的颜色,以及然后使用 setPixel()更改每个的颜色。您必须创建一个方法,返回具有某种颜色且未被另一种颜色阻挡的所有像素的数组(即,这样您就不会使用油漆桶并更改 all< /strong> 画布上的像素)。

可能也有此类东西的图书馆。

希望这能让您走上正轨。

I must warn you that getting this to work the same way that say Paint works will be actually pretty difficult.

I'd look at making your entire canvas a Bitmap.

Resources:

  1. Bitmap
  2. BitmapData (this one will have the key methods)

When shapes are drawn and whatnot, use the fillRect() method. For a tool like a paint bucket (like in paint), take a look at the floodFill() method.

I'm not really sure how could could create a paint bucket tool, but my mind is thinking along the lines of having a loop that uses getPixel() to check out the colours of each of the pixels surrounding where you click, and then uses setPixel() to change the colour of each. You'll have to create a method that returns an array of all the pixels that are of a certain colour and not blocked off by another colour (ie so you don't use the paint bucket and change the colour of all the pixels on the canvas).

There's likely libraries out there for this sort of stuff too.

Hope this gets you on the right track.

-柠檬树下少年和吉他 2024-11-22 08:39:02

或者只使用过滤器。请参阅 DisplayObject.filters

Or just use a filter. See DisplayObject.filters

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文