View Full Version : Remove Dynamically-Added .swf
douglaae
June 5th, 2007, 02:21 PM
Hi folks. I have an AS3 app that allows users to pick from a menu of AS2 .swf movies to load into a MovieClip. Users are allowed click to view one movie, but if they change their mind and click a different clip, it should unload/delete/remove the .swf that's currently playing so that the user don't have overlapping movies playing at once. If someone can help me to accomplish this, I would appreciate it! Here's what I've come up with, but it doesn't work:
try {
//(see the load code below) If a .swf is already loaded, remove it
var clipToDelete:Loader = Loader(parentClip.getChildAt(0));
parentClip.removeChild(clipToDelete);
clipToDelete = null;
}
catch (e) {
}
//Load a .swf into parentClip
var loader:Loader = new Loader();
parentClip.addChild(loader);
loader.addEventListener(Event.ADDED, parentClipOnLoad);
loader.load(new URLRequest("someMovie.swf");
Thanks!
Andy
famffc
June 5th, 2007, 02:43 PM
try this:
try {
//(see the load code below) If a .swf is already loaded, remove it
delete parentClip.removeChildAt(0);
}
catch (e) {
}
Also, I'm not sure if parentClip.addChild(loader); should only be called after the loader.load(new URLRequest("someMovie.swf");
ps: don't trust me... i just started to learn flash/ActionScript 1 day ago...
douglaae
June 6th, 2007, 09:13 AM
Thanks for your reply - it works with your code... sort of. The external movie that I'm loading in contains audio, and despite the video disappearing from the screen when the delete statement executes, the audio continues to play! I tried to use the stop() command, but it generates compiler errors during export. According to a post by senocular, you can't interact with AS1 or AS2 movies from AS3: http://www.kirupa.com/forum/showpost.php?p=1880488&postcount=20.
Is there a way to truly delete an AVM1Movie so that video and audio go away?
Thanks!
Andy
beet
November 20th, 2007, 12:19 PM
I need pretty much the same thing to happen when the various buttons in my sight are pressed, please can you show me how to modify the code to go into my as3? thanks very much
stop();
portfolio.addEventListener(MouseEvent.CLICK, clickHandler1);
function clickHandler2(event:MouseEvent):void {
gotoAndStop(4);
var pMain:Loader = new Loader();
addChild(pMain);
var url:URLRequest = new URLRequest("portfolio.swf");
pMain.load(url);
}
Felixz
November 20th, 2007, 05:19 PM
You jus remove that movie from display list... To truly remove it you must erase all references pointing at it then after some time it's automatically GarbageCollected. And you also must manually stop playback...
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.