Class Lifecycle in AS2.0
Jul 30
I’ve read about several people having this problem in AS2.0. If a class is imported in Frame 1 of their movie, it’s not accessible in Frame 10. The structure of the movie looks like the following:
Frame 1:
import com.db75.utils.ImageLoader;
Frame 10:
var myImageLoader:ImageLoader = new ImageLoader();
trace(myImageLoader);
This will trace “undefined” because the class doesn’t exist. Therefore the class only exists for the life of the current frame. This could be considered a limitation if you’re structuring your movie using frame states. One non-recommended workaround would be to import your class on every frame that makes reference to it. Another (better approach) would be to keep your movie as a single frame and handle any animation or state changes in components and child movieclips. This would all be controlled through your code so you would technically never need to leave frame 1 of your main (_root) movie.
There is a huge debate when it comes to the Flash developer community and whether to control your workflow through code or frame states. It’s considered bad practice in the community to use frame states because you might be loading a bunch of unnecessary code and components. It could also become more difficult to manage in the long run. Since Flash started as a designers tool, we’re all guilty of using frames to manage our workflow. In most cases it’s quicker/easier to get your application up and running. As of now I take the code approach and try to be more object oriented about my Flash development.
Read More