|
-
how to apply removeChild to multiple .swf's
Hello,
I have a project in which the user has the option of pressing any one of 5 keyboard keys that each loads a different .swf file. I would like whatever key the user presses to unload whatever swf is currently playing and load whichever one is associated with the key pressed.
I have no problem coding this with two .swf's --each one loads and simultaneously unloads the other-- however when I add a third, it becomes erratic and the third removeChild function does not work properly.
It would seem that the problem is that only one removeChild can be applied at a time. Is there a way around this?
The code I am using is on a frame within the main timeline and it is not associated with a container other than the stage onto which the the swf's are directly loaded:
Code:
//variables to call swf's
var myLoader:Loader = new Loader();
var myRequest:URLRequest=new URLRequest("swf/darker.swf");
var Loader2:Loader = new Loader();
var Request2:URLRequest=new URLRequest("swf/animalinside.swf");
var Loader3:Loader = new Loader();
var Request3:URLRequest=new URLRequest("swf/berlin1.swf");
//darker = myLoader : press keyboard #3 to load
stage.addEventListener(KeyboardEvent.KEY_DOWN, Darker);
function Darker(e:KeyboardEvent):void{
if (e.charCode == 51){ //51=3
myLoader.load(myRequest);
addChild(myLoader);
removeChild(Loader2);
removeChild(Loader3);
}
}
//animalInside = Loader2 : press keyboard #4 to load
stage.addEventListener(KeyboardEvent.KEY_DOWN, animalInside);
function animalInside(e:KeyboardEvent):void{
if (e.charCode == 52){ //52=4
Loader2.load(Request2);
addChild(Loader2);
removeChild(myLoader);
removeChild(Loader3);
}
}
//berlin1 = Loader3 : press keyboard #5 to load
stage.addEventListener(KeyboardEvent.KEY_DOWN, Berlin1);
function Berlin1(e:KeyboardEvent):void{
if (e.charCode == 53){ //53=5
Loader3.load(Request3);
addChild(Loader3);
removeChild(myLoader);
removeChild(Loader2);
}
}
I have tried adding multiple instances within the removeChild() parens like this: removeChild(Loader3, Loader2, Loader4, etc.); however it doesn't work.
Stacking the removeChild also doesn't seem to work:
removeChild(myLoader);
removeChild(Loader2);
removeChild(Loader3);
etc.
Not sure how to proceed, any help would be much appreciated!
Thanks in advance,
Llyfre
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|