-
Movie Clip Buttons & Dambusters
Hellote. I am a self-taught Flash developer and am learning ActionScript 2. Whilst programming a game known as "Dambusters", I encountered one of many problems with my amateur script. Most of them could be resolved, with I'm sure many flaws, but this snip of code doesn't seem to have anything wrong with it, and yet, it still fails to proceed the way I want it to.
In this game, or at least the prototype, a random brick on a field of 9 bricks (brick1, brick2, brick3...) within the movieclip "level_mc" will burst (or turn blue), and turn into the movieclip "burst_mc". One must click that movie clip to make gotoAndStop the frame in which it is once again neutral and waiting for the next burst. When the mouse rolls over the movieclip, the cursor becomes a hand, like it is supposed to, so I know some of this code is working, but when I click, it does not reset to "neutral."
function testForBrickFix()
{
var i = 1;
while (i <= 9)
{
eval("level_mc.brick" + i + ".burst_mc").onRelease = function ()
{
eval("level_mc.brick" + i).gotoAndStop("neutral");
};
++i;
} // end of while
} // Function ended
I'm hoping I can get some help and recommendations on this. I'll post more code to give other users an understanding if necessary.
-
Prid - Outing
READ THIS FIRST
Here's a fix:
Actionscript Code:
function testForBrickFix() { var i = 1; while (i <= 9) { btnClick(eval("level_mc.brick" + i + ".burst_mc"), eval("level_mc.brick" + i)); ++i; } // end of while } // Function ended
function btnClick(btn, mc){ btn.onRelease = function(){ mc.gotoAndStop("neutral"); } }
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Retro Game Scoring
Thank you, Nig 13! The code worked a lot better than I thought it would, as copy-pasting code, at least for me, always ends up with several compiler errors.
Well, then, I have some other things that aren't working. The function displayScore() tells the dynamic text field "score_display" to display six 0's, not just one, that resemble retro game scores. Here is the displayScore() code:
Actionscript Code:
function displayScore() { var extraDigits = 6 - gScore.toString().length; var display = ""; for (var digit = 1; digit <= extraDigits; ++loc1) { display = display + "0"; } // end of for display = display + gScore.toString(); score_display.text = display; } // Function ended
And here is the code you gave me with an added scoring function.
Actionscript Code:
function btnClick(btn, mc){ btn.onRelease = function(){ mc.gotoAndStop("neutral"); gScore = gScore + 250; }; } // Function ended
Alright, that should do it. Please fix if possible.
-
Senior Member
I think your for loop is messed up, the last statement is incrementing "loc1", try to change it to the following:
Code:
for (var digit = 1; digit <= extraDigits; digit++)
{
display = display + "0";
} // end of for
-
I seem to have another dilemma with the game. I set up a variable called "gOpenBricks", which starts out at 0. When a random brick opens, gOpenBricks is added to. It seems to work fine, except sometimes, the random brick generator generates a brick that is already open, and therefore, unnecessarily adds to gOpenBricks. I've tried several bits of code to make the game work so that if the brick is already open, when it generates that brick's number, it returns. This, hopefully, will work with the function "updateFlood", which tells the game how fast the rising flood is going depending on how many bricks are open. I first tried making a local variable called "brickIsOpen". Here's what the code for getRandomBrick looks like.
Actionscript Code:
function getRandomBrick() { var brickIsOpen = false; var randomNumber = random (9) + 1; eval("level_mc.brick" + randomNumber).gotoAndStop("burst"); brickIsOpen = true; ++gOpenBricks; trace (gOpenBricks); if (brickIsOpen) { gOpenBricks = gOpenBricks + 0; } // end if } // Function ended
After this, it still doesn't work. I thought an "else" function might work, but I don't have room for that. Hopefully, there is a good solution to this code, no matter how complex it may be.
-
Prid - Outing
EDIT: Sorry, Steven FN, I had this tab open for a long time
---------------------
Hi,
what's wrong with that code? It looks just fine, except for the increment part of the for loop. Have you declared loc1 variable? Try this for loop instead:
Actionscript Code:
for (var digit = 1; digit <= extraDigits; ++digit) { display = display + "0"; } // end of for
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|