Not too long ago I was given the task of making some old AS1 and AS2 games work inside a brand new AS3 site that we had built for a client. Whilst the basic concept seemed simple enough – load it in with a Loader – I soon realised there were a bunch of problems that needed to be addressed – most of which I couldn’t find any information on.
For the sake of others I have compiled a list of these here, along with the solutions I found, when there was one.
Levels are bad
I don’t know why, but they just don’t seem to work right. To get around it, I replaced I loaded external movies into the _root level, and then manuallky changed all the _levelN references. That was lots of fun. Good luck with that.
globalToLocal() may not work
This is a bit of a strange one. There appears to be a bug in conversion when the Loader that you use to load in the AVM1 file is positioned anywhere other than 0,0. Looking at the numbers it is almost like the position is offset by whatever amount the Loader is offset by.
Work around? Nothing really fun. You could write your own conversion thing that recursively climb up the _parent() tree – that’s all I came up with
MovieClip.hittest()
This seems to be related to the globalToLocal() bug in that the collision position is offset by the Loader offset. If you are just using the MovieClip.hittest(MovieClip) method, it will work fine because the co-ords are messed up fro both objects. Where it really fails though is when you are using the MovieClip.hittest(x,y,shape) approach. That just doesn’t play nice at all.
Steve, a guy I work with at VJ, came up with a bit of a work around. Basically you take the bounds of the object you are testing and then compare it to the point you want. This means you miss out on the shape flag, but it was good enough for a lot of the things I was doing.
Static classes / variables – (Updated – see note at end)
I still haven’t figured this one out fully yet, but there does seem to be a problem with static variables, etc.
One of the projects I was updating was using a Singleton style approach to one of its classes. It all worked fine the first time you loaded it in, but when you unloaded and reloaded it, it would fail.
I poked around for a fair while and I discovered that the class reference was staying in memory despite the AVM1 file being closed and unloaded. They by itself wasn’t that bad. The real issue was that the reference to _root and _global inside that class was totally lost.
Don’t get me wrong, _root and _global still exist in the project, but the static classes just didn’t see them at all – they kept coming up as null.
The work around for this wasn’t very elegant, but the only way we could get this to work was to pass in the _root reference to the static classes via an .init() call. Like I said, not pretty, but after a couple hours of experimenting it was the only thing that worked.
UPDATE This is just a quick update – I did a bit more research and it would appear that this bug is worse then I first thought. It has nothing to do with static classes and more to do with a bug in the player. Check out this bug notice on the adobe site, then pull a sad face if it is effecting you…. I know I will 🙁
That’s the list so far – if I find any others I will add them in as I go. Hopefully it will save people a bit of time.
another work around for MovieClip.hitTest(x,y,shape) :
make a movieClip with a 1×1 px shape, name it “hitTester” and set it _visible=false
then use this function :
function hitTestMc(mc, x, y){
hitTester._x = x;
hitTester._y = y;
return (mc.hitTest(hitTester));
}
I’ve got a similar problem with loading AS2 games in AS3. They have MovieClip-to-MovieClip hittests which, as you said, work fine. However, if you unload the game and then reload it, they stop working and the characters fall through the ground.
Still trying to figure that one out.