我正在尝试在Flash中创建一个按钮,暂停我文件中运行的所有影片剪辑。这些影片剪辑中没有一个是我主时间轴中的补间,它们都有各自的时间轴。每个移动剪辑都由一个按钮触发,该按钮告诉剪辑开始播放。所以,如果有人可以帮我创建这个暂停按钮,我将非常感激。谢谢你的时间。
答案 0 :(得分:3)
使用像这样的基类递归您想要暂停/恢复的所有符号,然后您不必遍历整个显示树:
package com.stackoverflow
{
import flash.display.MovieClip;
import flash.events.Event;
[Event(name="clipAdded", type="flash.events.Event")]
[Event(name="clipRemoved", type="flash.events.Event")]
public class BaseClip extends MovieClip
{
protected var baseClipChildren:Array;
protected var paused:Boolean = true;
public function BaseClip()
{
super();
baseClipChildren = new Array();
addEventListener(Event.ADDED_TO_STAGE, onAdded);
addEventListener("clipAdded", onClipAdded);
addEventListener(Event.REMOVED_FROM_STAGE, onRemoved);
addEventListener("clipRemoved", onClipRemoved);
}
protected function onAdded(event:Event):void
{
var target:BaseClip = event.target as BaseClip;
if(target == this) {
dispatchEvent(new Event("clipAdded", true));
}
}
protected function onClipAdded(event:Event):void
{
var target:BaseClip = event.target as BaseClip;
if(target && target != this) {
event.stopImmediatePropagation();
baseClipChildren.push(target);
}
}
protected function onRemoved(event:Event):void
{
var target:BaseClip = event.target as BaseClip;
if(target == this) {
dispatchEvent(new Event("clipRemoved", true));
}
}
protected function onClipRemoved(event:Event):void
{
var target:BaseClip = event.target as BaseClip;
if(target && target != this) {
event.stopImmediatePropagation();
baseClipChildren.splice(baseClipChildren.indexOf(target),1);
}
}
public function stopAll():void {
stop();
for each(var clip:BaseClip in baseClipChildren) {
clip.stopAll();
}
}
public function playAll():void {
play();
for each(var clip:BaseClip in baseClipChildren) {
clip.playAll();
}
}
}
}
答案 1 :(得分:2)
以下应该可以解决问题:
// create an array to store all playing movieclips
var playing = [];
// when a movieclip is played add it to the array like this:
// playing.push(myMovieClip);
// call this from your pause button's click handler
function pauseAll()
{
// loop through all the playing movieclips ...
for (var i = 0; i < playing.length; i ++)
{
// ... and stop them
playing[i].stop();
}
// now clear the array
playing = [];
}
答案 2 :(得分:0)
我不知道暂停所有影片片段的内置方式。
如果您保留对要在全局可访问对象中暂停的影片剪辑的引用,则可以遍历那些调用暂停的引用。
答案 3 :(得分:0)
此函数将停止对象的所有嵌套movieClip。只需通过您的舞台或顶级显示类来停止/播放所有内容。这样您就不必跟踪向阵列添加内容并且没有开销。
function recursiveStop(parentClip:DisplayObjectContainer, useStop:Boolean = true, gotoFrame:Object = null):void {
var tmpClip:MovieClip = parentClip as MovieClip;
if (tmpClip) {
if (useStop) {
(gotoFrame != null) ? tmpClip.gotoAndStop(gotoFrame) : tmpClip.stop();
}else {
(gotoFrame != null) ? tmpClip.gotoAndPlay(gotoFrame) : tmpClip.play();
}
}
var i:int = parentClip.numChildren;
while(i--){
if(parentClip.getChildAt(i) is DisplayObjectContainer){
recursiveStop(parentClip.getChildAt(i) as DisplayObjectContainer, useStop, gotoFrame);
}
}
}