Flash 需要gotoAndPlay,但由于生成方法的原因,不知道我的对象实例名称
我无法确定我的对象实例名称是什么,因为我是如何生成它们并将它们添加到后台的Flash 需要gotoAndPlay,但由于生成方法的原因,不知道我的对象实例名称,flash,actionscript-3,Flash,Actionscript 3,我无法确定我的对象实例名称是什么,因为我是如何生成它们并将它们添加到后台的 var circles:Array = new Array() //Declare array for displaying multiple objects function spawn(evt:MouseEvent):void { //MouseEvent trigger, working for (var i:int = 0; i<5; i++) { //Run five times circles[i
var circles:Array = new Array() //Declare array for displaying multiple objects
function spawn(evt:MouseEvent):void { //MouseEvent trigger, working
for (var i:int = 0; i<5; i++) { //Run five times
circles[i] = new circle(); //Make a new circle
stage.addChildAt(circles[i],1); //Layer control, no problem
circles[i].x = (stageCenterWidth*Math.random()*5)/(Math.random()*10);
circles[i].y = (stageCenterHeight*Math.random()*5)/(Math.random()*10);
}
}
var circles:Array=new Array()//声明用于显示多个对象的数组
函数spawn(evt:MouseEvent):void{//MouseEvent触发器,工作
对于(var i:int=0;i它将是这样的:
for each(var myCircle:circle in circles) {
myCircle.gotoAndStop(2);
}
function spawn(evt:MouseEvent):void { //MouseEvent trigger, working
for (var i:int = 0; i<5; i++) { //Run five times
var c:circle = new circle(); //Make a new circle
stage.addChildAt(circle,1); //Layer control, no problem
c.x = (stageCenterWidth*Math.random()*5)/(Math.random()*10);
c.y = (stageCenterHeight*Math.random()*5)/(Math.random()*10);
circles.push(c);
}
}
function gotoAndStopYourCircles(frameNumber:uint):void {
for (var c:circle in circles){
c.gotoAndStop(frameNumber);
}
}
更新:
根据您的评论,有很多选项(不同的数组等),但据我所知,我会为每批圆创建一个新容器…spawn()会创建一个新的精灵,将其添加到场景中,并将该批中的所有圆添加到该精灵中…然后,您可以逐批更改圆:
var lastSprite:Sprite = getChildAt(numChildren-1); // get the latest sprite added to "this" (I suggest not using stage.addChild)
for(var i:uint = 0; i < lastSprite.numChildren; i++) { //for each child of that sprite
lastSprite.getChildAt(i).gotoAndStop(2); //goto 2
}
var lastSprite:Sprite=getChildAt(numChildren-1);//将最新的Sprite添加到“this”(我建议不要使用stage.addChild)
对于(vari:uint=0;i
它会是这样的:
for each(var myCircle:circle in circles) {
myCircle.gotoAndStop(2);
}
function spawn(evt:MouseEvent):void { //MouseEvent trigger, working
for (var i:int = 0; i<5; i++) { //Run five times
var c:circle = new circle(); //Make a new circle
stage.addChildAt(circle,1); //Layer control, no problem
c.x = (stageCenterWidth*Math.random()*5)/(Math.random()*10);
c.y = (stageCenterHeight*Math.random()*5)/(Math.random()*10);
circles.push(c);
}
}
function gotoAndStopYourCircles(frameNumber:uint):void {
for (var c:circle in circles){
c.gotoAndStop(frameNumber);
}
}
更新:
根据您的评论,有很多选项(不同的数组等),但据我所知,我会为每批圆创建一个新容器…spawn()会创建一个新的精灵,将其添加到场景中,并将该批中的所有圆添加到该精灵中…然后,您可以逐批更改圆:
var lastSprite:Sprite = getChildAt(numChildren-1); // get the latest sprite added to "this" (I suggest not using stage.addChild)
for(var i:uint = 0; i < lastSprite.numChildren; i++) { //for each child of that sprite
lastSprite.getChildAt(i).gotoAndStop(2); //goto 2
}
var lastSprite:Sprite=getChildAt(numChildren-1);//将最新的Sprite添加到“this”(我建议不要使用stage.addChild)
对于(vari:uint=0;i
我认为你需要遍历整个显示列表,查找circle类的所有对象并相应地采取行动。
我认为你需要遍历整个显示列表,查找circle类的所有对象并相应地采取行动。
当你想做这样的事情时,我会给你一个提示。不要把它添加到舞台上直接,因为还有其他DisplayObject绑定也将直接添加到舞台上,这将使你更难完成你想做的事情
function gotoandstopcircles(container:DisplayObjectContainer):void{
var circ:*;
for (var i:uint=0; i < container.numChildren; i++){
circ = container.getChildAt(i);
if (circ is circle){
circ.gotoAndStop(2);
}
else if(circ is DisplayObjectContainer){
gotoandstopcircles(circ);
}
}
}
制作一个您选择的DisplayObjectContainer
,无论是MovieClip
还是Sprite
。就个人而言,我会使用Sprite
来保存您的MovieClip
我们将它们移动到它们自己的容器中的原因是,我们可以迭代特定对象的所有子对象,并对每个子对象执行操作;在您的例子中,播放第2帧
var container:Sprite = new Sprite();
var circles:Array = new Array() //Declare array for displaying multiple objects
function spawn(evt:MouseEvent):void { //MouseEvent trigger, working
for (var i:int = 0; i<5; i++) { //Run five times
circles[i] = new circle(); //Make a new circle
container.addChildAt(circles[i],1); //Layer control, no problem
circles[i].x = (stageCenterWidth*Math.random()*5)/(Math.random()*10);
circles[i].y = (stageCenterHeight*Math.random()*5)/(Math.random()*10);
}
}
var容器:Sprite=newsprite();
var circles:Array=new Array()//声明用于显示多个对象的数组
函数spawn(evt:MouseEvent):void{//MouseEvent触发器,工作
对于(var i:int=0;i当你想做这样的事情时,我会给你一个提示。不要直接将它添加到stage,因为还有其他DisplayObject绑定也会直接添加到stage,这会使你更难做你想做的事情
制作一个您选择的DisplayObjectContainer
,无论是MovieClip
还是Sprite
。就个人而言,我会使用Sprite
来保存您的MovieClip
我们将它们移动到它们自己的容器中的原因是,我们可以迭代特定对象的所有子对象,并对每个子对象执行操作;在您的例子中,播放第2帧
var container:Sprite = new Sprite();
var circles:Array = new Array() //Declare array for displaying multiple objects
function spawn(evt:MouseEvent):void { //MouseEvent trigger, working
for (var i:int = 0; i<5; i++) { //Run five times
circles[i] = new circle(); //Make a new circle
container.addChildAt(circles[i],1); //Layer control, no problem
circles[i].x = (stageCenterWidth*Math.random()*5)/(Math.random()*10);
circles[i].y = (stageCenterHeight*Math.random()*5)/(Math.random()*10);
}
}
var容器:Sprite=newsprite();
var circles:Array=new Array()//声明用于显示多个对象的数组
函数spawn(evt:MouseEvent):void{//MouseEvent触发器,工作
对于(var i:int=0;i您使用以下代码:
var circles:Array = new Array() //Declare array for displaying multiple objects
function spawn(evt:MouseEvent):void { //MouseEvent trigger, working
for (var i:int = 0; i<5; i++) { //Run five times
circles[i] = new circle(); //Make a new circle
stage.addChildAt(circles[i],1); //Layer control, no problem
circles[i].x = (stageCenterWidth*Math.random()*5)/(Math.random()*10);
circles[i].y = (stageCenterHeight*Math.random()*5)/(Math.random()*10);
}
}
您可以使用以下代码:
var circles:Array = new Array() //Declare array for displaying multiple objects
function spawn(evt:MouseEvent):void { //MouseEvent trigger, working
for (var i:int = 0; i<5; i++) { //Run five times
circles[i] = new circle(); //Make a new circle
stage.addChildAt(circles[i],1); //Layer control, no problem
circles[i].x = (stageCenterWidth*Math.random()*5)/(Math.random()*10);
circles[i].y = (stageCenterHeight*Math.random()*5)/(Math.random()*10);
}
}
如果动画可以立即开始,甚至可以立即在创建圆圈的for循环中。圆圈[i]。gotoAndPlay(2);这让我走上了正确的道路。问题是,在这种情况下,gotoAndPlay(2);仅适用于显示的最后5个圆圈。我在舞台上有最新的5+15。有没有办法针对在舞台上显示的那些最近几次for循环已运行的圆圈?或者如果动画可以立即启动,甚至可以立即在创建圆圈的for循环中。圆圈[I]。gotoAndPlay(2);这让我走上了正确的道路。问题是,在这种情况下,gotoAndPlay(2);只在显示的最后5个圆圈上起作用。我在舞台上有最新的5+15。有什么方法可以针对在舞台上显示的那些最近几次运行for循环的圆圈?