function clickFunctionpr1(evt:MouseEvent):void {
var containerpr1:Sprite = new Sprite();
containerpr1.name = "eprinting1";
addChild(containerpr1);
containerpr1.y = 137;
containerpr1.x = 214;
var pngpr1Ldr:Loader = new Loader();
var pngpr1URL:String = "images/pr1.png"
var pngpr1URLReq:URLRequest = new URLRequest(pngpr1URL);
pngpr1Ldr.load(pngpr1URLReq);
pngpr1Ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, pngpr1Loaded);
function pngpr1Loaded(event:Event):void
{
containerpr1.addChild(pngpr1Ldr.content);
}
this.checkContainerspr();
stop();
}
function clickFunctionpr2(evt:MouseEvent):void {
var containerpr2:Sprite = new Sprite();
containerpr2.name = "eprinting1";
addChild(containerpr2);
containerpr2.y = 137;
containerpr2.x = 214;
var pngpr2Ldr:Loader = new Loader();
var pngpr2URL:String = "images/pr2.png"
var pngpr2URLReq:URLRequest = new URLRequest(pngpr2URL);
pngpr2Ldr.load(pngpr2URLReq);
pngpr2Ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, pngpr2Loaded);
function pngpr2Loaded(event:Event):void
{
containerpr2.addChild(pngpr2Ldr.content);
}
this.checkContainerspr();
stop();
}
var containerpr:Array = new Array("eprinting1");
function childOnStagepr( name:String ):Boolean{
return this.getChildByName( name ) != null && this.getChildByName( name).parent != null ? true : false;
}
function checkContainerspr():void{
for( var i:uint = 0; i < this.container.length; i++){
if( childOnStagepr( this.container[i] ) ){
removeChild( this.getChildByName( this.container[i] ) );
}
}
}
doch irgendwie will Flash mir den container nicht leeren, wenn ich auf den verschiedenen Buttons(buttonpr1 und buttonpr2) klicke.
Dein Problem liegt hier.
1. Wer zum Geier ist container, du meintest bestimmt den containerpr
ActionScript:
1 2 3 4 5 6
function checkContainerspr():void{
for( var i:uint = 0; i < this.container.length; i++){
if( childOnStagepr( this.container[i] ) ){
removeChild( this.getChildByName( this.container[i] ) );
}
}
Es könnte also so aussehen. Ich habe mir erlaubt deine childOnStagepr auch zu ändern. Du wirst aber sehen, dass dies auch nicht zum gewünschten ergebnis führt, da du zuerst die container füllst und dann wieder löschst. Kleiner Tipp: merke dir doch die container (Sprites) im Array und nicht die Namen, dann könne man sagen containerpr[i].parent.removeChild(containerpr[i]). Ist natürlich noch die Frage, wo du hinwillst, wo sagst du dem Array später welche objekte gelöscht werden sollen, gibt es immer nur einen oder mehrere etc....
ActionScript:
1 2 3 4 5 6 7 8 9 10 11 12
function childOnStagepr( name:String ):DisplayObject{
return this.getChildByName( name ) || this.getChildByName( name).parent;
}
function checkContainerspr():void{
for( var i:uint = 0; i < this.containerpr.length; i++){
var removeMe:DisplayObject = childOnStagepr( this.containerpr[i]);
if( removeMe != null ){
this.removeChild(removeMe);
}
}
}
PS: kleiner Fehler bei mir, sehe gerade this.getChildByName( name).parent der kann in checkContainerspr natürlich so nicht gelöscht werden. Ich werde das jetzt nicht ändern, da ich nicht genau verstehe, was du damit bezwecken willst.---------------------------------------------- www.flashdevelop.de
12.01.12, 18:50 #Jobs Flash Freelancer für ca. 2 Wochen in München gesucht http://t.co/XpMJr5dv
10.01.12, 10:45 #PureMVC vs #RobotLegs Performance Battle. PureMVC is significantly faster than RobotLegs in nearly every respect. http://t.co/324gWRAr