12-29-2008, 02:24 AM
|
#1
|
|
Registered User
Join Date: Dec 2008
Posts: 13
|
[AS2] My First Actionscript Project - Coinflip Game
I've been studying for months and finally decided to create a project. It's a simple coin flip game in which I'm 95% finished. Unfortunately, I ran into a glitch that I can't figure out, relating to the removeMovieClip() method. Here is my code for the project:
ActionScript Code:
this.createEmptyMovieClip("canvas_mc", 1);
canvas_mc._x = 140;
canvas_mc._y = 90;
canvas_mc.attachMovie("Heads", "Heads_mc", canvas_mc.getNextHighestDepth(), {_x:canvas_mc._x, _y:canvas_mc._y});
var headsTails:Number;
var i:Number = 0;
function flip():Number {
headsTails = (Math.round(Math.random()));
return headsTails;
}
function removeTails() {
//removeMovieClip(canvas_mc.target.name);
removeMovieClip(canvas_mc.CoinSpin_tails_mc+[i]);
//canvas_mc.CoinSpin_tails_mc[+i].removeMovieClip;
//trace(canvas_mc.CoinSpin_tails_mc[+i].name);
//removeMovieClip(canvas_mc.CoinSpin_tails_mc1);
//removeMovieClip(canvas_mc.CoinSpin_tails_mc2);
//removeMovieClip(canvas_mc.CoinSpin_tails_mc3);
//removeMovieClip(canvas_mc.CoinSpin_tails_mc4);
//removeMovieClip(canvas_mc.CoinSpin_tails_mc5);
}
function removeHeads() {
//removeMovieClip(canvas_mc.target.name);
removeMovieClip(canvas_mc.CoinSpin_heads_mc+[i]);
//canvas_mc.CoinSpin_heads_mc[+i].removeMovieClip;
//removeMovieClip(canvas_mc.CoinSpin_heads_mc1);
//removeMovieClip(canvas_mc.CoinSpin_heads_mc2);
//removeMovieClip(canvas_mc.CoinSpin_heads_mc3);
//removeMovieClip(canvas_mc.CoinSpin_heads_mc4);
//removeMovieClip(canvas_mc.CoinSpin_heads_mc5);
}
flip_btn.onPress = function() {
flip();
removeHeads();
removeTails();
removeMovieClip(canvas_mc.Heads_mc);
//removeMovieClip(canvas_mc.target.name);
i++;
if (headsTails == 0) {
trace('tails');
canvas_mc.attachMovie("CoinSpin_tails", "CoinSpin_tails_mc"+i, canvas_mc.getNextHighestDepth(), {_x:canvas_mc._x, _y:canvas_mc._y});
} else {
trace('heads');
canvas_mc.attachMovie("CoinSpin_heads", "CoinSpin_heads_mc"+i, canvas_mc.getNextHighestDepth(), {_x:canvas_mc._x, _y:canvas_mc._y});
}
};
I'm actually trying to get this counter to work. I left the commented lines in the above code to show some of the things I've tried; //removeMovieClip(canvas_mc.CoinSpin_heads_mc1); do what I need to do but I can't get the counter to work properly. All my other attempts to remove the movie clips did not work except when I targeted them directly with the number at the end.
|
|
|
12-29-2008, 02:31 AM
|
#2
|
|
Banned by AS.org Staff
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
|
Attach your .fla to this forum...
|
|
|
12-29-2008, 04:41 AM
|
#3
|
|
Registered User
Join Date: Dec 2008
Posts: 13
|
FLA File Attached
Here is the fla file, (I haven't put the final graphics in it yet).
|
|
|
12-29-2008, 05:09 AM
|
#4
|
|
Banned by AS.org Staff
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
|
A bit confused...
Are you saying that as it is, this is working as you would want it to, or not?
Or that on every press after the first press of the flip button, the result clip should be removed and I should only see the flipping movement as I first saw on the firts press?
Am I making sense?
|
|
|
12-29-2008, 06:22 AM
|
#5
|
|
Banned by AS.org Staff
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
|
Think all you need is this...
ActionScript Code:
stop();
this.createEmptyMovieClip("canvas_mc", 1);
canvas_mc._x = 140;
canvas_mc._y = 90;
canvas_mc.attachMovie("Heads", "Heads_mc", canvas_mc.getNextHighestDepth(), {_x:canvas_mc._x, _y:canvas_mc._y});
var headsTails:Number;
var i:Number = 0;
function flip():Number {
headsTails = (Math.round(Math.random()));
return headsTails;
}
flip_btn.onPress = function() {
canvas_mc.Heads_mc.removeMovieClip();
flip();
if (headsTails == 0) {
//trace('tails');
canvas_mc.attachMovie("CoinSpin_tails", "CoinSpin_tails_mc"+i, 10, {_x:canvas_mc._x, _y:canvas_mc._y});
} else {
//trace('heads');
canvas_mc.attachMovie("CoinSpin_heads", "CoinSpin_heads_mc"+i, 10, {_x:canvas_mc._x, _y:canvas_mc._y});
}
};
In fact attaching either clip to the same depth - I choose 10, rather than getNextHighestDepth() - automatically removes the previous clip that was attached to that depth...
|
|
|
12-30-2008, 04:11 AM
|
#6
|
|
Registered User
Join Date: Dec 2008
Posts: 13
|
Thanks!
It seems like I tried everything but that! It works fine now.
I guess that's a bit of a gotcha when using getNextHighestDepth()
|
|
|
12-30-2008, 04:15 AM
|
#7
|
|
Banned by AS.org Staff
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
|
Grrrrreat!
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 08:49 PM.
///
|
|