AS3 / removeChild之/的addChild通过点击按钮 [英] AS3 / removeChild/addChild by clicking button
问题描述
我有几个电影剪辑成一个帧中的阶段的大小,并予有通过这些网页之间的按钮,切换
I have several movie clips into a frame the size of the stage and I have to switch through a button between those pages.
所以,如果我preSS按钮,应该所有的其他帧removeChild之和的之一,他被称为去的addChild。
So if I press button, should all the other frames removeChild and the one where he is called to go addChild.
编辑:我有动作放置在影片剪辑的时间轴中使按键不会在舞台上,但我把影片剪辑使用动作脚本
I have the actionscript placed in the timeline of the movieClip so the button is not on the stage but I put in the movie clip using action script.
那么,什么DodgerThud这里显示是不可能的,因为按钮,因为这改变了在影片剪辑(的)。
So what DodgerThud showed here is not possible because the button has changed since that is in the movieClip('s).
我想我需要把相同的code在每一个动画片段。
I think I need to place the same code in every movieClip.
推荐答案
把所有的影片剪辑到一个Vector或数组。
Put all of your MovieClips into a Vector or Array.
当你点击按钮,你应该循环通过矢量/阵列,并检查当前的影片剪辑在舞台上与包含项(DisplayObject)
。如果影片剪辑是目前在舞台上,将其删除,并添加另一个舞台,例如,下一个在矢量/阵列。
When you click the button, you should cycle through the Vector/Array and check if the MovieClip is currently on stage with contains(DisplayObject)
. If the Movieclip IS currently on the stage, remove it and add another one to the stage, for example, the next one in the Vector/Array.
var vec:Vector.<MovieClip> = new Vector.<MovieClip>
vec[0] = new MovieClip();
vec[1] = new MovieClip(); //example with MovieClips
vec[2] = new MovieClip();
addChild(vec[0]); //add one of the MovieClips to stage
button.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
for(var i:int = 0; i < vec.length; i++) //go through the Vector one by one
{
if(contains(vec[i]) //if the Object at position i in the Vector is on stage
{
removeChild(vec[i]); //remove the Object
var next:int = i; //create a temporary holder
if(next == vec.length) //check if the displayed Object was the last in the list
{
next = 0; //if so, set to 0
}else{
next++; //otherwise, only add 1
}
addChild(vec[next]); //add the next Object to the stage. If the removed Object was the last in the Vector, it'll add the first Object in the Vector to the list
break; //escape the for loop, otherwise it'll always only show the last Object
}
}
}
这篇关于AS3 / removeChild之/的addChild通过点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!