Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-10-2010, 02:02 PM   #1
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default [AS2] removeMovieClip

how do i remove the movieclip


ActionScript Code:
box.onEnterframe = function(){     btn.onPress = function(){     box.removeMovieClip();         } }



Ive also tried neither worked

ActionScript Code:
box.onEnterframe = function(){     btn.onPress = function(){     this.removeMovieClip();         }     }
hansolo is offline   Reply With Quote
Old 11-10-2010, 03:00 PM   #2
asf8
Senior Member
 
Join Date: Apr 2007
Posts: 4,772
Default

1.) Why are you using an onEnterFrame to monitor a onPress? That is a waste of resources and not needed.

2.) Unless your MovieClip was created using duplicateMovieClip, createEmptyMovieClip or attachMovie, your code wont work. This is described in the helps files....

Quote:
MovieClip.removeMovieClip method
http://livedocs.adobe.com/flash/9.0/...=00001965.html

Removes a movie clip instance created with duplicateMovieClip(), MovieClip.duplicateMovieClip(), MovieClip.createEmptyMovieClip(), or MovieClip.attachMovie().

This method does not remove a movie clip assigned to a negative depth value. Movie clips created in the authoring tool are assigned negative depth values by default. To remove a movie clip that is assigned to a negative depth value, first use the MovieClip.swapDepths() method to move the movie clip to a positive depth value.
3. Are you targeting the proper scope of box in relationship to btn?

Those are the things I would consider.
asf8 is offline   Reply With Quote
Old 11-11-2010, 06:06 AM   #3
nick.marshal
Registered User
 
Join Date: Oct 2010
Posts: 23
Default

You can use unloadMovie function.
nick.marshal is offline   Reply With Quote
Old 11-11-2010, 09:41 AM   #4
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

ive realised that nowi need to attach the movie to the stage. I tried the enterframe becuse the clip was not removing.

ActionScript Code:
var movieclip = attachMovie("clip","clip_one",this.getNextHighestDepth); btn.onPress = function(){ movieclip.removeMovieClip(); }  //problem solved_____________________________________________

just a query
now the reason for me removing the movieclip . my method at the present time.
add point in a game is to make the coin invisible. use alpha function. and move the collected coins to side of the stage

if i totally remove the coins, the score is not kept.

now this not a problem as the player can not see the collected coins .

I dont think this method is best way.

Ive heard an

Object() keeps the movieclips properties when even when removed
from the stage.



my example below is what i have been using. ive not included my whole code. im sure its not neccessary. To move the invisible movieclips to side of stage. if remove the moveiclip totally the score lost.The movieclips properties are no longer available. This why i used this method below.


ActionScript Code:
for(i =0; i< coin_array.length; i++){ if(player.hitTest(coins[i])){ coiin_score +=1; // add score coins[i]._alpha = 0;// make coin invisible coins[i]._x = 0;// move coin to side of stage. off game area } }

Last edited by hansolo; 11-11-2010 at 09:50 AM.
hansolo is offline   Reply With Quote
Old 11-11-2010, 12:33 PM   #5
tacos
Grrrrrrrrreat!
 
tacos's Avatar
 
Join Date: Apr 2007
Location: Montréal, Québec
Posts: 5,473
Default

Is the coiin_score variable a local variable to the movie clip?

If so you may want to make it a main timeline or other parent movie clip variable instead so that, the score isn't lost when removing the movie clip.
__________________
WHO I WAS...
BANDS OF THE 80's
tacos is offline   Reply With Quote
Old 11-11-2010, 02:15 PM   #6
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

hi tacos

i place the score varible on the main timeline scipt as below

as an example below shows


ActionScript Code:
var score:Number =0;// on the maintimeline if(player.hitTest(coinArray[i])){ score += 1; }
hansolo is offline   Reply With Quote
Old 11-11-2010, 02:31 PM   #7
tacos
Grrrrrrrrreat!
 
tacos's Avatar
 
Join Date: Apr 2007
Location: Montréal, Québec
Posts: 5,473
Default

And so? Is it now working properly?
__________________
WHO I WAS...
BANDS OF THE 80's
tacos is offline   Reply With Quote
Old 11-11-2010, 03:19 PM   #8
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

Im afraid not. that why i used the method below as i explained.



if you remove a movieclip totally off the stage the properties of the movieclip dissapear. including the score added . its not on a clipevent.
This applys to when the score is on the main script.

if hitthemoveclip add score.

try it and you will see. i could be wrong.
hansolo is offline   Reply With Quote
Old 11-11-2010, 06:23 PM   #9
tacos
Grrrrrrrrreat!
 
tacos's Avatar
 
Join Date: Apr 2007
Location: Montréal, Québec
Posts: 5,473
Default

Are you saying that if you remove a coin movie clip, you're loosing the value of a main timeline variable named score?
__________________
WHO I WAS...
BANDS OF THE 80's
tacos is offline   Reply With Quote
Old 11-12-2010, 07:52 AM   #10
hansolo
Senior Member
 
Join Date: Feb 2008
Posts: 1,059
Default

Ive just tried it and actualy the score is fine. I thought when ive moved movieclip before i lost the score.

I have moved the frame to the second level and one point is deducted.
when the timeline moves. I set up some quick code below as a test.
Ive removed the array, to enable to move the coins at different distances


you could copy and paste this check for the one point deducted.


ActionScript Code:
var coins_collected:Number = 0; player.onEnterFrame = function(){         score_box.text = coins_collected;     //_________________________________________________________ // move player if (Key.isDown(Key.LEFT)){ player._x -=5; } if (Key.isDown(Key.RIGHT)){ player._x +=5; } if (Key.isDown(Key.UP)){ player._y -=5; } if (Key.isDown(Key.DOWN)){ player._y +=5; } //_________________________________________________________ //collect coins if(player.hitTest(coin_one)){ coins_collected +=1; coin_one._x = 0;// 1 point coin_one._alpha } if(player.hitTest(coin_two)){ coins_collected +=1; coin_two._x = 0//  a point  wont be added as movieclip off stage } if(player.hitTest(coin_three)){ coins_collected +=1; coin_three._x = -400//  a point  added even when off stage/ sorry my mistake } //_________________________________________________________ // complete level  two if(coins_collected == 3){ // at level   two ( 1 coins deducted) gotoAndStop("level_two") } }
















how ever if move frames the score is no longer kept
hansolo 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


All times are GMT. The time now is 03:44 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.