无法在AS3中的动画片段上创建过滤器(Can't create filter on movieclips in AS3)

编程入门 行业动态 更新时间:2024-10-05 23:25:27
无法在AS3中的动画片段上创建过滤器(Can't create filter on movieclips in AS3)

经过长时间的闪光挣扎......

我有一些动画片段,我想只对我MOUSE_OVER的动画片段进行过滤。

对于每个动画片段,必须采用与MOUSE_OVER和MOUSE_OUT类型不同的方式。

After a long time of struggling with flash...

I have some movieclips and I would like to get a filter only to that movieclip that I MOUSE_OVER.

There must be a different way than type MOUSE_OVER and MOUSE_OUT for every single movieclip.

最满意答案

你可以通过几种方式解决这个问题。

最好:

使用继承。

如果您创建的类文件具有一组项的所有常用功能,则可以让MovieClip继承该功能。 因此,您将在根目录中创建一个如下所示的文件。 (我们称之为FilteredMC.as )

package { import flash.events.MouseEvent; public class FilteredMC extends MovieClip { //the function that matches the name of class, is what runs when the object is created public function FilteredMC():void { this.addEventListener(MouseEvent.MOUSE_OVER, mouseOver); this.addEventListener(MouseEvent.MOUSE_OUT,mouseOut); } private function mouseOver(e:MouseEvent):void { this.filters = [...your filter...] } private function mouseOut(e:MouseEvent):void { this.filters = []; } } }

然后在FlashPro中,右键单击应具有此功能的库对象,转到“ 属性 ”,然后选择“export for actionscript”,然后在“ 基类 ”文本字段中输入: FilteredMC 。 把你想要的任何东西作为类名(只要它是唯一的,不与任何其他类或关键字冲突)


好:

如果所有项目都是容器的唯一子项,则可以循环遍历该容器的所有子项并添加代码:(您也可以使用一组项目执行此操作)

var i:int = containerMC.numChildren; while(i--){ if(containerMC.getChildAt(i) is MovieClip){ setupFilter(containerMC.getChildAt(i) as MovieClip); } } function setupFilter(mc:MovieClip):void { mc.addEventListener(MouseEvent.MOUSE_OVER, mouseOver); mc.addEventListener(MouseEvent.MOUSE_OUT,mouseOut); } function mouseOver(e:MouseEvent):void { //the event's 'currentTarget' property is the item you added the listener to MovieClip(e.currentTarget).filters = [...your filter...] } function mouseOut(e:MouseEvent):void { MovieClip(e.currentTarget).filters = []; }

There are a few ways you could go about this.

Best:

use inheritance.

If you create a class file that has all the common functionality of a group of items, you can have your MovieClips inherit that functionality. So you'd create a file in your root directory that looks like this. (let's call it FilteredMC.as)

package { import flash.events.MouseEvent; public class FilteredMC extends MovieClip { //the function that matches the name of class, is what runs when the object is created public function FilteredMC():void { this.addEventListener(MouseEvent.MOUSE_OVER, mouseOver); this.addEventListener(MouseEvent.MOUSE_OUT,mouseOut); } private function mouseOver(e:MouseEvent):void { this.filters = [...your filter...] } private function mouseOut(e:MouseEvent):void { this.filters = []; } } }

Then in FlashPro, right click your library objects that should have this functionality, go to "properties", and choose "export for actionscript" then in the "base class" text field, put: FilteredMC. Put whatever you'd like as the class name (so long as it's unique and doesn't clash with any other class or keyword)


Good:

If all your items are the sole children of a container, you can loop through all the children of that container and add the code: (you could also do this with an array of items)

var i:int = containerMC.numChildren; while(i--){ if(containerMC.getChildAt(i) is MovieClip){ setupFilter(containerMC.getChildAt(i) as MovieClip); } } function setupFilter(mc:MovieClip):void { mc.addEventListener(MouseEvent.MOUSE_OVER, mouseOver); mc.addEventListener(MouseEvent.MOUSE_OUT,mouseOut); } function mouseOver(e:MouseEvent):void { //the event's 'currentTarget' property is the item you added the listener to MovieClip(e.currentTarget).filters = [...your filter...] } function mouseOut(e:MouseEvent):void { MovieClip(e.currentTarget).filters = []; }

更多推荐

本文发布于:2023-07-09 10:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   片段   动画   filter   create

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!