This code work fine in AS2, but how do you change it to AS3? I want to see the different between AS2 and AS3 and try to learn more about AS3.
Code:
//======= fireBullet creates a bullet and attaches a moveBullet behaviour to its onEnterFrame event
//
function fireBullet() {
numBombs = getNextHighestDepth();
attachMovie("bomb", "aBomb" + numBombs, numBombs);
this["aBomb" + numBombs].onEnterFrame = moveBullet;
with (this["aBomb" + numBombs]) {
_xscale = _yscale = 75;
_x = theTank._x;
_y = theTank._y - theTank._height / 2;
}
}
//
// ====== Basically moves each bullet up the screen; when it hits the top edge, or the bottom of the info_txt box,
// we create and attach an explosion symbol at the point of contact, then remove the associated Bullet movie clip.
//
function moveBullet() {
this._y -= 10;
hit = this.hitTest(alien_mc);
if (this._y < 0 || this.hitTest(_root["info_txt"]) || hit) {
numExplosions = getNextHighestDepth();
_root.attachMovie("explosion_mc", "explosion" + numExplosions, numExplosions);
// ==== swapDepths just swaps the depths of two movieclips. Since we created info_txt first, it is "beneath" all of the other clips we've created.
// swapping the depths "brings it the the front". Try commenting out the line below to see why we need to swap. Can you explain what happens?
//=================================
_root["explosion" + numExplosions].swapDepths(_root["info_txt"]);
_root["explosion" + numExplosions].onEnterFrame = function() {
// response to the EnterFrame event for the explosion movie clip: don't want to loop exploding so get rid of ourselves after a single play;
// uses the _currentframe & _totalframes properties to see if we've got to the end of the mc.
if (this._currentframe > this._totalframes - 1) {
removeMovieClip(this);
}
};
with (_root["explosion" + numExplosions]) {
_x = this._x;
_y = this._y + 10;
_xscale = _yscale = 50;
}
removeMovieClip(this);
if (hit) {
with (alien_mc) {
_x = Math.random() * 500 + 20;
_y = 0;
}
}
}
}