1

I know the AS3 Loader's class unloadAndStop() supposes to unload and stop everything on a SWF's stage when I load one, but does it also changes objects within the library (even if they are not on stage?).

I'll describe my problem to clear it up: I am loading SWFs dynamically into my AS3 application and extract required symbols from them using applicationDomain and getDefinition. The stage of the SWF/FLA I am loading is empty, and all I have are exported symbols in my library.

The problem happens when I load symbols which have pre-compiled clips inside of them (in my case, a Partigen emitter, but I don't think it really matters), which probably has event listeners or timers - the code on these clips stops working and acts weird when unloadAndStop() is called by the Loader which loaded the clip's parent SWF. I assumed unloadAndStop() removes a required event listener from it, but not sure why (again, it's not on the stage).

I'd write my own kind of unloadAndStop() that filters these pre-compiled clips or checks what's truly going on there, but I am pretty sure that unloadAndStop() does things which are unavailable through the API.

What can explain this behavior? Anyone can think of a possible solution? Thank you.

ShayDavidson
  • 717
  • 1
  • 7
  • 20
  • 1
    unloadAndStop removes the instance of what you're loading and removes all listeners associated with it. If you're using classes with getDefinition, you're not making copies of those classes/symbols/movieclips in the library, you're using direct instances of them (not a clone). If you unloadAndStop them, you are explicitly telling all of those to unload, hence you won't have access to them. – jpea Mar 09 '11 at 13:57
  • hopefully that helps btw - unloadAndStop isn't very well documented on Adobe's site last I checked... most of the info on it was found in the user community and it's still pretty sparse. – jpea Mar 09 '11 at 14:01
  • 1
    Why do you need to use unloadAndStop() at all? Are you running this application on a tightly resource-constrained embedded system? Your use case, if I understand it correctly, sounds perfect for just loading a swf and "forgetting about it" on a desktop machine. Why unload the resources when you might need them again? – scriptocalypse Mar 09 '11 at 15:04
  • Actually I use all the symbols I extract with getDefinition() after the unloadAndStop() without any problem. Some of them even have code. I save the Class generated by getDefinition() in a Dictionary and then instantinize it when I want. The one which doesn't work well, is using code taken from a pre-compiled library (Partigen). I believe that if I would unload even the classes, I wouldn't be able to create instances like I described above (yet I do). What seems to be happening is that it removes event listeners from the code itself while preserving it without the listeners. – ShayDavidson Mar 09 '11 at 15:43

1 Answers1

0

Make your loader in this way:

myLoader.contentLoaderInfo.addEventListener( Event.INIT , myLoaderHandler, false, 0, true);

It solves some problems due to unloadAndStop().

Katax Emperore
  • 465
  • 1
  • 8
  • 29