Skip to main content
May 14, 2010
Question

Best practice?

  • May 14, 2010
  • 1 reply
  • 616 views

If a swf file is destined to be loaded into a container file and interacted with from there, is it considered better practice for the code for the interaction to reside in the loaded file or the container file? I am writing on the timeline, rather than creating classes.

Also if a movie clip on the stage contains buttons with event listeners attached and I remove the movie clip as a child, do the event listeners disappear with it, or should i remove them separately?

Thanks for your help.

This topic has been closed for replies.

1 reply

May 14, 2010

Well, best practice is to use classes... but if you're going to use timeline code then it's mostly a matter of preference. Though personally I think it makes more sense to put code pertinent to the swf's being loaded in those swfs. Then it's kind of like classes at least, as the code is encapsulated within the object... and if you have a lot of different movies to load you don't want all their code in your one loader - it's no fun wading through two thousand lines of code inside one movie.

Removing a clip, with removeChild does nothing except remove it from the display list. All code, event listeners, memory the object consumes, etc. continue to function.

May 15, 2010

Thanks for the reply - that clears a lot up. So if removing a child, would it be best to rmove all it's event listeners first. Also say the child (movie  clip) in question held the content for one page a site. It is something that the user may or may not return to, and they will be looking at other pages/children in the meantime; is it therfore best to make the original movie clip null and recreate an instance of it from the library when it is needed.

Which begs the question: if you make an object null does that remove all it's associated event listeners?

Participating Frequently
May 18, 2010

Hi,

If you declared your listeners' weak argument to true, you won't have to bother with removing those listeners before a "quit". Weakly declared listeners will no longer affect anything once the object is not on the display list.

mc.addEventListener("event",func,false,0,true);

Since I've read this recommendation from gskinner (read about weakly referenced listeners), I adopted this way of coding.

The only thing is, you should beware of anonymous functions, as it is mentioned in Skinner's article.

For what I could see from actually trying this method, you won't have any problem with your listeners working when weakRef is set to true for a class declared property, but the listener won't work if you do the same on a var created  inside a function.

____________________

Design Cyboïde

Designer web Montréal