Recent posts by refrag on Kongregate

Flag Post

Topic: Game Programming / Using _root frames, bad practice?

Ok I think I see what you’re doing now. You have movieclips that have code and variables in them. These movieclips are being added to frames in the main timeline.

Yes that would cause a problem. What happens is every time you hit a keyframe where that moveclip “appears”, it would call its constructor and probably wipe out your saved variables.

I again revert back to my previous post in recommending that no code exists on frames. I also recommend not manually adding objects to your stage. If you force yourself to set your stage up using code, you then force yourself to properly handle constructors and what-not.

_global variables is a dangerous road to go down and can lead to debugging hell if done incorrectly. You’ll be stronger in the long-run if you just stick to proper Object-Oriented-Programming principles.

Flag Post

Topic: Game Programming / Using _root frames, bad practice?

One of the first things I’ve learned with Actionscript 3 is to avoid coding on the timeline. This was a bad habit I picked up back in the Flash4/5 days when you had to do this sort of thing.

The main timeline of all my AS3 projects are single frame and there aren’t even any objects on the stage. By keeping all of my code in an external .as file I’m able to keep better control of my variables and objects.

The only time I use MovieClips with any frames in their timelines is if those movieclips are animations I want to call. And even then I instantiate them from a .as file and control their timelines programatically. The extent of my frame code is now “stop();” or the occasional “gotoAndPlay(2);”

But maybe I’m just blabbing… if you can explain a bit more what you are trying to do?

Flag Post

Topic: Game Programming / Having large numbers of objects in AS2 -& How to turn movieclip into a bitmap and print on the ground?

A potentially useful tutorial would be 8bitrocket’s ‘blit’ tutorials. I’ve recently used these to build a tile engine. You can kind of extend these concepts to do what you need. Basically I’d store each “bit” in an array. You’d need some sort of x,y, and reference ID in that array. You’d then need to determine which “bits” were in view. Using the array data, you’d draw these bits onto a buffer Bitmap or directly onto a viewpane Bitmap. I’d keep the “bit” itself as a Bitmap object type instead of a movieclip to make bitmap copy functions easier. If you really want to retain some movieClip animations, you can even do what you are currently doing, then at the end of the animation, removeSelf() and replace with static bitmap data to conserve memory.

So you’d have your “bit” constructor create itself onscreen as a movie clip, run through what it needs to do, then call its destructor. Within its destructor you’d add the proper x,y,id values to your bitTracking Array() and finally remove the movieclip from the stage. Your bitTracking Array() would provide the information nessisary for you to do bitmap copy functions to only paint the bits that are viewable on screen.