在 Flash CS4 AS3.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 flash.filters.ColorMatrixFilter - 链接文档中有示例。
使用 Tweener 的 ColorShortcuts 通过分配 < code>_Color 属性是一个十六进制颜色值。此外,此方法还可以让您通过选择为所需的
time
属性分配一个非零值来轻松淡入颜色。请记住,任何位图过滤器(例如阴影)或形状的任何子项(如果它是精灵)也会改变颜色。尽管使用容器来分离形状的每个元素也同样容易。
[编辑] 您可以使用 ColorTransform 对象可轻松更改显示对象的颜色。这也是AS3中最常见的做法。这是一个示例:
上面的代码绘制了一个红色矩形,将其添加到舞台上,然后使用 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 requiredtime
property.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:
the above code draws a red rect, adds it to the stage and then uses a ColorTransform object to change its color to blue.
我必须警告您,要使其像 Paint 那样工作实际上非常困难。
我会考虑将整个画布设为
位图
。资源:
位图
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:
Bitmap
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 thefloodFill()
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 usessetPixel()
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.
或者只使用过滤器。请参阅 DisplayObject.filters
Or just use a filter. See
DisplayObject.filters