我可以同时控制加载的 swf 中影片剪辑的多个实例吗?

发布于 2024-10-19 21:28:17 字数 236 浏览 6 评论 0原文

我正在通过加载器类将在 flash professional cs5 中创建的 swf 加载到 Flex 4.1 应用程序中。 Flash 文件包含为动作脚本导出的多个影片剪辑,并且这些影片剪辑存在于整个电影的许多实例中。

迭代所有内容,比较类类型似乎是解决这个问题最简单但也是最冗余的方法。有没有办法使用类名作为一种全局选择器来访问剪辑?

我还可以让 Flash 中的子剪辑侦听它们执行操作的事件,但我不太确定什么是最好的。

I am loading an swf created in flash professional cs5 via the loader class into a flex 4.1 application. The flash file contains multiple movieclips that are exported for actionscript and those movieclips exist in many instances throughout the movie.

Iterating through everything, comparing class types seems to be the most easy but also the most redundant way to solve this. Is there any way of using the class name as a kind of global selector to access the clips?

I could also make the sub-clips in the flash listen for an event on which they perform an action, but I am not really sure what might be best.

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

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

发布评论

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

评论(2

像你 2024-10-26 21:28:17

在这种情况下,我发现解决问题的一个好方法是创建一个可静态访问的类,该类管理在实例化时向其注册的其他类的实例。举个例子...

public class GlobalStopper{
    private static var clips:Array = [];
    public static function add(mc:MovieClip):void{
        clips.push(mc);
    }
    public static function stop():void{
        var mc:MovieClip;
        for(var i:int = 0, ilen:int = clips.length ; i < ilen ; i++){
            mc = clips[i] as MovieClip;
            if (mc) mc.stop();
        }
    }
}

并且...

public class GloballyStoppableMovieClip extends MovieClip{

    public function GloballyStoppableMovieClip(){
        GlobalStopper.add(this);
    }

}

GloballyStoppableMovieClip 的任何和所有实例都会立即向 GlobalStopper 注册,因此调用

GlobalStopper.stop(); 

...将停止所有已注册的影片剪辑。

您可以添加任何您想要的其他功能。此外,您可以让它接受实现您的 movieclip 子类(或也可能需要停止和播放的非 movieclip 对象!)的公共函数 stop() 和 play() 的 Istoppable 或 IPlayable 对象,而不是添加接受 MovieClip 实例!然后实施。

但对于类似 jQuery 的选择器呢?这并不是我处理这个特定问题的方式。

In cases like these, I find that a good way to solve the problem is to create a statically accessable class that manages instances of other classes that are registered with it on instantiation. As an example...

public class GlobalStopper{
    private static var clips:Array = [];
    public static function add(mc:MovieClip):void{
        clips.push(mc);
    }
    public static function stop():void{
        var mc:MovieClip;
        for(var i:int = 0, ilen:int = clips.length ; i < ilen ; i++){
            mc = clips[i] as MovieClip;
            if (mc) mc.stop();
        }
    }
}

and...

public class GloballyStoppableMovieClip extends MovieClip{

    public function GloballyStoppableMovieClip(){
        GlobalStopper.add(this);
    }

}

Any and all instances of GloballyStoppableMovieClip are instantly registered with the GlobalStopper, so calling

GlobalStopper.stop(); 

...will stop all registered movieclips.

You can add in any other functions you want. Furthermore, instead of having add accept MovieClip instances, you could have it accept IStoppable or IPlayable objects that implement public functions stop() and play() that your movieclip subclass (or non-movieclip object that also might need to stop and play!) then implements.

But as for jQuery-like selectors? Not really the way I'd handle this particular issue.

习惯成性 2024-10-26 21:28:17

我想把它打出来就可以了。我使用了事件解决方案:

在根时间轴中我放置了一个这样的函数:

function cause():void {
    dispatchEvent(new Event("do stuff",true));
}

在库剪辑的主时间轴中是:

DisplayObject(root).addEventListener("do stuff", function (e:Event=null) {
    ... whatever ...         
});

这很脏,但你明白了。

i guess typing it out did the trick. i used the event solution:

in the root timeline i placed a function like this:

function cause():void {
    dispatchEvent(new Event("do stuff",true));
}

and in the library clip's main timeline goes:

DisplayObject(root).addEventListener("do stuff", function (e:Event=null) {
    ... whatever ...         
});

this is dirty but you get the idea.

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