Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-29-2008, 02:24 AM   #1
jcbrady89
Registered User
 
Join Date: Dec 2008
Posts: 13
Default [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.

jcbrady89 is offline   Reply With Quote
Old 12-29-2008, 02:31 AM   #2
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

Attach your .fla to this forum...
atomic is offline   Reply With Quote
Old 12-29-2008, 04:41 AM   #3
jcbrady89
Registered User
 
Join Date: Dec 2008
Posts: 13
Default FLA File Attached

Here is the fla file, (I haven't put the final graphics in it yet).
Attached Files
File Type: zip coinflip02.fla.zip (12.1 KB, 131 views)
jcbrady89 is offline   Reply With Quote
Old 12-29-2008, 05:09 AM   #4
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

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?
atomic is offline   Reply With Quote
Old 12-29-2008, 06:22 AM   #5
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

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...
atomic is offline   Reply With Quote
Old 12-30-2008, 04:11 AM   #6
jcbrady89
Registered User
 
Join Date: Dec 2008
Posts: 13
Default 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()
jcbrady89 is offline   Reply With Quote
Old 12-30-2008, 04:15 AM   #7
atomic
Banned by AS.org Staff
 
Join Date: Jan 2007
Location: Montréal, Québec
Posts: 14,073
Default

Grrrrreat!
atomic is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Embed WAV file in Flex Builder 3 / ActionScript project? chrisnyc Flex 2, 3 & 4 11 11-30-2012 10:13 PM
Game Development in Actionscript 3.0 -- Flash vs Flex nonim99 Gaming and Game Development 12 11-14-2008 12:30 PM
help on my actionscript game kai361 Gaming and Game Development 2 12-07-2007 03:36 PM
Game Project Help Needed - Willing to Pay Sublim30 Projects and Positions 1 10-21-2004 08:07 AM
Mi First time with flash ActionScript & game fastzone Site Check 3 01-23-2002 03:04 PM


All times are GMT. The time now is 05:11 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.