I know this is old news and most of you have just left timelines and mc's
for dead and moved on. But I'm having a hard time believing AS3 screwed us
this bad. I'm also just now getting hip enough with as3 to understand the
topic.
I've created a little test case involving a parent.swf and a child.swf.
There is zero code on either timeline and their document classes are listed
below.
parent.swf has 2 frames and child.swf has 30.
Some key clean up is purposely left out to test the weak references, garbage
collector and for the sake of discussion. I don't normally use timelines for
anything. I'm just trying to get a clear understanding.
>>Parent.as
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.events.*;
public class Parent extends MovieClip {
var url:URLRequest;
var loader:Loader;
//target_mc is a stage instance (automatic declaration turned off)
//target_mc does not exist on frame 2
public var target_mc:MovieClip;
public function Parent() {
stop();
init();
}
private function init():void
{
url = new URLRequest("Child.swf");
loader = new Loader();
loader.load(url);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
onLoadComplete, false, 0, true);
}
private function onLoadComplete(e:Event):void
{
var c:MovieClip = e.target.content;
target_mc.addChild(c);
}
}
}
>>Child.as
package {
import flash.display.MovieClip;
import flash.events.*;
public class Child extends MovieClip {
var count:uint = 0;
public function Child() {
addEventListener(Event.ENTER_FRAME, onEnterFrame, false, 0,
true);
this.addFrameScript(29, onFrame29);
}
private function onEnterFrame(e:Event):void
{
trace(this+" "+count++);
}
private function onFrame29():void {
stop();
trace("frame 29 " + parent);
(parent.parent as MovieClip).gotoAndStop(2);
}
}
}
The goal here is see the output eventually stop tracing. Obviously I could
remove the Enter Frame event listener before sending parent to frame 2 but
what I want to be sure of is the memory taken up by child.swf is freed up.
How would I gaurantee this happening?
--
--Joel Stransky
stranskydesign.com
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders