删除子项和错误 2025
我想通过另一个类删除一个孩子(背景)。我似乎无法瞄准它!它总是返回 null 或错误 2025 之类的东西......呵呵。
我的类creationObjets中有背景:
package cem{
import flash.display.Sprite;
public class creationBackground extends Sprite{
public function creationBackground() {
switch(monterJeu._Difficulte){
case 0:
backgroundFacile();
break;
case 1:
backgroundMoyen();
break;
case 2:
backgroundDifficile();
break;
}
}
private function backgroundFacile():void{
var backgroundStage:Sprite = new Sprite();
backgroundStage.graphics.beginFill(0x8FCCA8);
backgroundStage.graphics.moveTo(0,0);
backgroundStage.graphics.lineTo(750,0);
backgroundStage.graphics.lineTo(750,450);
backgroundStage.graphics.lineTo(0,450);
backgroundStage.graphics.lineTo(0,0);
backgroundStage.graphics.endFill();
this.addChild(backgroundStage);
}
private function backgroundMoyen():void{
var backgroundStage:Sprite = new Sprite();
backgroundStage.graphics.beginFill(0x8F3378);
backgroundStage.graphics.moveTo(0,0);
backgroundStage.graphics.lineTo(750,0);
backgroundStage.graphics.lineTo(750,450);
backgroundStage.graphics.lineTo(0,450);
backgroundStage.graphics.lineTo(0,0);
backgroundStage.graphics.endFill();
this.addChild(backgroundStage);
}
private function backgroundDifficile():void{
var backgroundStage:Sprite = new Sprite();
backgroundStage.graphics.beginFill(0x233378);
backgroundStage.graphics.moveTo(0,0);
backgroundStage.graphics.lineTo(750,0);
backgroundStage.graphics.lineTo(750,450);
backgroundStage.graphics.lineTo(0,450);
backgroundStage.graphics.lineTo(0,0);
backgroundStage.graphics.endFill();
this.addChild(backgroundStage);
}
}
}
public static var _creationBackground:creationBackground = new creationBackground();
下面,我添加它:
addChild(_creationBackground);
然后我想从另一个类actionObjets中删除它!我怎样才能了解我的背景? 我尝试了
creationObjets._creationBackground.parent.removeChild(creationObjets._creationBackground);
removeChild(creationObjets._creationBackground);
我真的不知道如何访问它!
I'd like to remove a child (background) via another class. I can't seem to be able to target it! It always returns me null or error 2025 and stuff... hehe.
I have the background in my class creationObjets:
package cem{
import flash.display.Sprite;
public class creationBackground extends Sprite{
public function creationBackground() {
switch(monterJeu._Difficulte){
case 0:
backgroundFacile();
break;
case 1:
backgroundMoyen();
break;
case 2:
backgroundDifficile();
break;
}
}
private function backgroundFacile():void{
var backgroundStage:Sprite = new Sprite();
backgroundStage.graphics.beginFill(0x8FCCA8);
backgroundStage.graphics.moveTo(0,0);
backgroundStage.graphics.lineTo(750,0);
backgroundStage.graphics.lineTo(750,450);
backgroundStage.graphics.lineTo(0,450);
backgroundStage.graphics.lineTo(0,0);
backgroundStage.graphics.endFill();
this.addChild(backgroundStage);
}
private function backgroundMoyen():void{
var backgroundStage:Sprite = new Sprite();
backgroundStage.graphics.beginFill(0x8F3378);
backgroundStage.graphics.moveTo(0,0);
backgroundStage.graphics.lineTo(750,0);
backgroundStage.graphics.lineTo(750,450);
backgroundStage.graphics.lineTo(0,450);
backgroundStage.graphics.lineTo(0,0);
backgroundStage.graphics.endFill();
this.addChild(backgroundStage);
}
private function backgroundDifficile():void{
var backgroundStage:Sprite = new Sprite();
backgroundStage.graphics.beginFill(0x233378);
backgroundStage.graphics.moveTo(0,0);
backgroundStage.graphics.lineTo(750,0);
backgroundStage.graphics.lineTo(750,450);
backgroundStage.graphics.lineTo(0,450);
backgroundStage.graphics.lineTo(0,0);
backgroundStage.graphics.endFill();
this.addChild(backgroundStage);
}
}
}
public static var _creationBackground:creationBackground = new creationBackground();
below, I add it:
addChild(_creationBackground);
then I want to remove it from another class actionObjets! How can I get to my background?
I tried
creationObjets._creationBackground.parent.removeChild(creationObjets._creationBackground);
removeChild(creationObjets._creationBackground);
I really have no idea how to access it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否正确理解您的问题,但是:
请记住,为了删除孩子,您需要访问孩子的舞台。如果您的 actionObjects 类是 Movieclip 或 sprite,它将有一个引用舞台的只读变量(该变量可能与您添加 _creationBackground 的舞台相同,也可能不同)。
例如:
如果 actionObjets 与您添加 _creationBackground 的位置具有相同的阶段,则应该可以正常工作。
如果actionObjets没有相同的stage或根本没有(也许它不是sprite或movieclip?),您可以传入添加了_creationBackground的stage。
IE:
package {
}
然后尝试:
这当然是假设您有权访问 actionObjets 内的 _creationBackground 剪辑。
不确定这是否解决了您的问题,
祝你好运。
I'm not sure if I understand your problem correctly but:
Remember that in order to remove a child you need access to the child's stage. If your actionObjects class is a Movieclip or sprite it will have a read-only variable that will reference the stage (which may or may not be the same as the stage you added _creationBackground too).
So for instance:
Should work fine if actionObjets has the same stage as wherever you added _creationBackground.
If actionObjets does not have the same stage or has none at all (maybe it isn't a sprite or movieclip?) You can pass in the stage where _creationBackground was added.
IE:
package {
}
and then try:
This is of course assuming that you have access to the _creationBackground clip inside actionObjets.
Not sure if this addressed your problem or not,
good luck.
以下任何一项都应该足够:
或
或
当您使用removeChildAt() 或getChildAt() 时,您必须指定显示对象的(您想要获取或删除的)索引位置。索引位置是显示对象在显示对象容器的显示列表中的位置(我假设它是0)。
此外,当使用 getChildByName() 时,您必须指定要获取的显示对象的名称。请注意,您必须首先设置显示对象的 name 属性。
下面是一个基于 Flash 应用程序/电影的工作示例:
在文档类 Main 中,首先导入 CreationObjet 和 ActionObjet。接下来,声明、实例化 CreationObjet 的实例并将其添加到舞台中。最后声明并实例化 ActionObjet 的实例,并将 CreationObjet 的实例解析为其唯一参数。
在CreationObjet 类中,CreationBackground 的实例被添加到CreationObjet 显示对象中。
最后在 ActionObjet 类中,CreationBackground 显示对象从 CreationObjet 中删除。
我不得不对您的 Flash 应用程序/电影做出一系列假设,但这应该能让您大致了解如何实现我之前建议的内容。
我希望这有帮助:)
Any of the following should suffice:
or
or
When you use removeChildAt() or getChildAt() you must specify the display object's(that you want to get or remove) index position. The index position is the position of the display object in the display list of the display object container(I've made the assumption that its 0).
Also when using getChildByName() you must specify the name of the display object that you want to get. Note that you must set the name property of the display object first.
Here's a working example based on you flash app/movie:
In the document class Main, first CreationObjet and ActionObjet is imported. Next an instance of the CreationObjet is declared, instantiated and added to the stage. Lastly an instance of the ActionObjet is declared, instantiated and the instance of CreationObjet is parsed as its only argument.
In the CreationObjet class, an instance of CreationBackground is added to the CreationObjet display object.
Finally in ActionObjet class, the CreationBackground display object is removed from the CreationObjet.
I've had to make a bunch of assumptions about your flash app/movie, but this should give you a general idea of how to implement what I suggested before.
I hoped this helped :)