在不提供对象名称的情况下清除 DisplayObject()
Clear DisplayObject() without giving object name
我正在尝试制作一个 Flash 应用程序,当单击第一个按钮时,displayObject 函数将显示图像。当点击第二个按钮时,前一个持有人需要清除里面的所有物体,这就是我卡住的部分。有什么解决办法吗?
function showOppo (e:Event):void
{
if(holder_1.stage)
{
holder_1 = new MovieClip();
holder_2 = new MovieClip();
holder_3 = new MovieClip();
}
holder_1.x = 37.6;
holder_1.y = 133.05;
holder_2.x = 458.55;
holder_2.y = 133.05;
Of9.scaleX = 1;
Of9.scaleY = 1;
Ofx.scaleX = 1;
Ofx.scaleY = 1;
holder_1.addChild(Of9);
holder_2.addChild(Ofx);
stage.addChild(holder_1);
stage.addChild(holder_2);
stage.setChildIndex(holder_1,1);
stage.setChildIndex(holder_2,1);
}
function showsamsung (e:Event):void
{
if(holder_1.stage)
{
holder_1 = new MovieClip();
holder_2 = new MovieClip();
holder_3 = new MovieClip();
}
holder_1.x = 37.6;
holder_1.y = 133.05;
holder_2.x = 458.55;
holder_2.y = 133.05;
Sgn9.scaleX = 1;
Sgn9.scaleY = 1;
Ss10.scaleX = 1;
Ss10.scaleY = 1;
holder_1.addChild(Sgn9);
holder_2.addChild(Ss10);
stage.addChild(holder_1);
stage.addChild(holder_2);
stage.setChildIndex(holder_1,1);
stage.setChildIndex(holder_2,1);
}
在我使用的代码中 new MovieClip()
但是当点击第二个按钮时没有任何反应。点击第二个按钮后,我返回并再次点击第一个按钮,显示第二个的功能。
"I try to find out how to delete the existing child of each holder since if not, all those image will stack together"
是的,当您 addChild
时,就像告诉 Flash "paste this on a new layer inside the target"
。每一层称为一个深度级别。您可以使用 getChildAt(x)
访问特定的 layer/depth,其中 x
是图层编号(first=0
、second=1
、third=2
等..)
示例:
假设您有一个支架(例如: holder_1
)用于显示所有图像。
1) 第一次使用 holder_1.addChild(pic1);
添加子图像
所以现在 pic1
存在于 holder_1
.
的(层)级别 0 内
2) 添加第二张图片 holder_1.addChild(pic2);
所以现在 pic2
存在于 holder_1
目标内的(层)级别 1。
现在两个图像堆叠在同一容器内的不同层上。怎么修?考虑这个逻辑:
holder_1.addChild(pic2); //add pic2 into holder (at level 0)
holder_1.removeChildAt(0); //remove anything at level 0 (...is pic2)
holder_1.addChild(pic1); //add different pic1 into holder (at level 0)
您的代码可以这样尝试:
holder_1 = new MovieClip();
holder_2 = new MovieClip();
holder_3 = new MovieClip();
holder_1.x = 37.6; holder_2.x = 458.55;
//# give multiple VARS the same value
holder_1.y = holder_2.y = 133.05;
stage.addChild(holder_1);
stage.addChild(holder_2);
btnoppo.addEventListener(MouseEvent.CLICK,showOppo);
btnsamsung.addEventListener(MouseEvent.CLICK,showsamsung);
function showOppo (e:Event):void
{
//# set multiple at once to value = 1
Of9.scaleX = Of9.scaleY = Ofx.scaleX = Ofx.scaleY = 1;
//# check if already has image & remove it
if(holder_1.getChildAt(0) != null) { holder_1.removeChildAt(0); }
if(holder_2.getChildAt(0) != null) { holder_2.removeChildAt(0); }
holder_1.addChild(Of9); holder_2.addChild(Ofx);
}
function showsamsung (e:Event):void
{
Sgn9.scaleX = Sgn9.scaleY = Ss10.scaleX = Ss10.scaleY = 1;
//# check if already has image & remove it
if(holder_1.getChildAt(0) != null) { holder_1.removeChildAt(0); }
if(holder_2.getChildAt(0) != null) { holder_2.removeChildAt(0); }
holder_1.addChild(Sgn9); holder_2.addChild(Ss10);
}
我正在尝试制作一个 Flash 应用程序,当单击第一个按钮时,displayObject 函数将显示图像。当点击第二个按钮时,前一个持有人需要清除里面的所有物体,这就是我卡住的部分。有什么解决办法吗?
function showOppo (e:Event):void
{
if(holder_1.stage)
{
holder_1 = new MovieClip();
holder_2 = new MovieClip();
holder_3 = new MovieClip();
}
holder_1.x = 37.6;
holder_1.y = 133.05;
holder_2.x = 458.55;
holder_2.y = 133.05;
Of9.scaleX = 1;
Of9.scaleY = 1;
Ofx.scaleX = 1;
Ofx.scaleY = 1;
holder_1.addChild(Of9);
holder_2.addChild(Ofx);
stage.addChild(holder_1);
stage.addChild(holder_2);
stage.setChildIndex(holder_1,1);
stage.setChildIndex(holder_2,1);
}
function showsamsung (e:Event):void
{
if(holder_1.stage)
{
holder_1 = new MovieClip();
holder_2 = new MovieClip();
holder_3 = new MovieClip();
}
holder_1.x = 37.6;
holder_1.y = 133.05;
holder_2.x = 458.55;
holder_2.y = 133.05;
Sgn9.scaleX = 1;
Sgn9.scaleY = 1;
Ss10.scaleX = 1;
Ss10.scaleY = 1;
holder_1.addChild(Sgn9);
holder_2.addChild(Ss10);
stage.addChild(holder_1);
stage.addChild(holder_2);
stage.setChildIndex(holder_1,1);
stage.setChildIndex(holder_2,1);
}
在我使用的代码中 new MovieClip()
但是当点击第二个按钮时没有任何反应。点击第二个按钮后,我返回并再次点击第一个按钮,显示第二个的功能。
"I try to find out how to delete the existing child of each holder since if not, all those image will stack together"
是的,当您 addChild
时,就像告诉 Flash "paste this on a new layer inside the target"
。每一层称为一个深度级别。您可以使用 getChildAt(x)
访问特定的 layer/depth,其中 x
是图层编号(first=0
、second=1
、third=2
等..)
示例:
假设您有一个支架(例如: holder_1
)用于显示所有图像。
1) 第一次使用
holder_1.addChild(pic1);
添加子图像 所以现在pic1
存在于holder_1
. 的(层)级别 0 内
2) 添加第二张图片
holder_1.addChild(pic2);
所以现在pic2
存在于holder_1
目标内的(层)级别 1。
现在两个图像堆叠在同一容器内的不同层上。怎么修?考虑这个逻辑:
holder_1.addChild(pic2); //add pic2 into holder (at level 0)
holder_1.removeChildAt(0); //remove anything at level 0 (...is pic2)
holder_1.addChild(pic1); //add different pic1 into holder (at level 0)
您的代码可以这样尝试:
holder_1 = new MovieClip();
holder_2 = new MovieClip();
holder_3 = new MovieClip();
holder_1.x = 37.6; holder_2.x = 458.55;
//# give multiple VARS the same value
holder_1.y = holder_2.y = 133.05;
stage.addChild(holder_1);
stage.addChild(holder_2);
btnoppo.addEventListener(MouseEvent.CLICK,showOppo);
btnsamsung.addEventListener(MouseEvent.CLICK,showsamsung);
function showOppo (e:Event):void
{
//# set multiple at once to value = 1
Of9.scaleX = Of9.scaleY = Ofx.scaleX = Ofx.scaleY = 1;
//# check if already has image & remove it
if(holder_1.getChildAt(0) != null) { holder_1.removeChildAt(0); }
if(holder_2.getChildAt(0) != null) { holder_2.removeChildAt(0); }
holder_1.addChild(Of9); holder_2.addChild(Ofx);
}
function showsamsung (e:Event):void
{
Sgn9.scaleX = Sgn9.scaleY = Ss10.scaleX = Ss10.scaleY = 1;
//# check if already has image & remove it
if(holder_1.getChildAt(0) != null) { holder_1.removeChildAt(0); }
if(holder_2.getChildAt(0) != null) { holder_2.removeChildAt(0); }
holder_1.addChild(Sgn9); holder_2.addChild(Ss10);
}