PDA

View Full Version : Coding works with Flash 6 but not 8



ACFan120
August 18th, 2010, 08:59 PM
I have this bit of coding for a game that I need help with.
The code is supposed to duplicate a movieclip, (that's already on the frame), on one end of the screen, move them to the other side of the screen, and move it back to the other side. The original file has the player at Flash 6. But when I increase the player to Flash 8, the player of the full Game, It doesn't appear to work. When I increase the SWF to full size, though, the Movieclip is at the Loading point of the screen. I don't know why it does this, and it's crucial that I recieve help. I will include a link to download the FLA down below, but in case someone could just look at the code, here it is:

Movieclip's coding:
onClipEvent (load) {
function reset() {
this._x = 575;
this._y = math.random()*335;
enemySpeed = (math.random()*6)+5;
}
reset();
}
onClipEvent (enterFrame) {
this._x -= enemySpeed;
if (this._x<-22) {
reset();
}
if (this.hitTest("bullet")){
gotoAndStop(8)
}
}
Frame's actionscript:
stop();
var numEnemy = 5;
_root.score = 0;
var fire = false;
var enemy = 10;
function moveHero(speed) {
//check if key is down
if (Key.isDown(Key.LEFT)) {
_root.hero._x -= speed;
} if (Key.isDown(Key.RIGHT)) {
_root.hero._x += speed;
} if (Key.isDown(Key.UP)) {
_root.hero._y -= speed;
} if (Key.isDown(Key.DOWN)) {
_root.hero._y += speed;
}
if (Key.isDown(65)) {
if (fire == false) {
fireBullets();
}
}
}
var i = 1;
function fireBullets() {
i++;
fire = true;
_root.hero.gotoAndPlay(2);
var newname = "bullet"+i;
_root.attachMovie("bullet", newname, i*100);
_root[newname]._y = _root.hero._y-5;
_root[newname]._x = _root.hero._x+12;
_root[newname].onEnterFrame = function() {
var bullet_speed = 9;
this._x += bullet_speed;
if (this._x>655) {
this.removeMovieClip();
}
for (var h = 1; h<=numEnemy; h++) {
if (this.hitTest(_root["enemy"+h])) {
this.removeMovieClip();
_root["enemy"+h].play();
//trace("enemy"+h);
}
}
};
}
function Enemys() {
for (j=1; j<=numEnemy; j++) {
var name = "enemy"+j;
_root.enemy1.duplicateMovieClip(name, j);
}
}
Enemys();
_root.onEnterFrame = function() {
moveHero(enemy);
};
Now for the download Link:
http://www.mediafire.com/?4hlot1wmgwdo6id

senocular
August 19th, 2010, 10:35 AM
I can't see all the code on my phone but usually version issues like this are because of capitalization. Double check that in your code

pradvan
August 19th, 2010, 11:58 AM
Place this on your enemy clip:



onClipEvent(load)
{
this._x = 575;
this._y = Math.random()*335;
this.enemySpeed = Math.random()*3
}
onClipEvent(enterFrame)
{
this._x -= enemySpeed;
if (this._x < -22) {
reset();
}
if (this.hitTest("bullet")){
gotoAndStop(8)
}

function reset()
{
this._x = 575;
this._y = math.random()*335;
enemySpeed = (math.random()*6)+5;
}
}



That being said, your hitTest is not going to work because you have no way of knowing how many bullets are on the stage outside of the enemy clip code.

The best way to do this is to move all the code to the first frame (like you have for the hero).

Create new enemies by using attachMovie from the library and putting those enemy clips in an array via the .push method.

When you create bullets, you should also place them in an array. That way you can check if movieclips in bulletsArray are hitting any clips in enemiesArray.

ACFan120
August 19th, 2010, 12:44 PM
Thank you, pradvan, it works (with a bit of Modifying)! Also, I can get the hitTest to work, except for one enemy that appears on the screen, which I assume to be the actual movieclip, and not one of the duplicates. I'm just gonna leave it in there, if I can't find a way to fix it.

For your help, you will appear in the credits of the game. Thank you!

pradvan
August 19th, 2010, 12:57 PM
Oh wait, you're that guy that was really mean and obnoxious a couple of weeks ago.

I'll be sure to look at people's names next time I help someone...

:hang:

ACFan120
August 19th, 2010, 02:03 PM
Who, me?

pradvan
August 19th, 2010, 02:21 PM
Who, me?

http://www.kirupa.com/forum/showthread.php?t=352479

Just realized that I tried to basically tell you the same thing in the previous thread; use arrays.

You just don't want to learn. Whatever dude.

:zipper:

ACFan120
August 19th, 2010, 02:23 PM
Oh... sorry :(