Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-11-2007, 01:13 AM   #1
tagdigital
Registered User
 
Join Date: Nov 2006
Posts: 55
Default remove movie clip

I have a class that represents a symbol in the library. Inside the class I set a timer to create a fade effect. I create the instance from main and add it to a layer, like this. fadeLayer.addChild(fadeSymbol);
Everything works fine. What I want to do is have the symbol remove itself after it is finished fading. My problem is I can't figure out how to remove it from inside the class. something like this....?? this.parent.removeChild(this). I know that's a mess but it shows what I want to do. Also I want to delete it so there are not multiple invisible instances of this object around. So after I remove it from its parent I want to delete it.

Thanks.
tagdigital is offline   Reply With Quote
Old 07-11-2007, 02:53 AM   #2
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,140
Default

a stripped down class code would really help out, but remember the DisplayObject's parent is always the DisplaysObjectConainer. therefore _target.parent.removeChild(_target); should do the trick.

But lets see some simple sample code.
__________________
trace("Good bye Flash.") Log.i(TAG, "Hello Droid");
Flash Gordon is offline   Reply With Quote
Old 07-11-2007, 02:55 AM   #3
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

Hey, tagdigital,

I'm just getting the hang of AS3 myself. Well, somewhat. So this was a fun little exercise. I just made a simple circle movie clip and associated it with a class using Linkage in the library.

The code in the main fla:
ActionScript Code:
var myBall:SelfDelete = new SelfDelete(); myBall.x = 100; myBall.y = 100; addChild(myBall);
The code in SelfDelete.as:
ActionScript Code:
package {     import flash.events.TimerEvent;     import flash.utils.Timer;     import flash.display.MovieClip;     public class SelfDelete extends MovieClip     {         private var rt:Timer;         public function SelfDelete()         {             rt = new Timer(100, 50);             rt.addEventListener(TimerEvent.TIMER, fadeMe);             rt.addEventListener(TimerEvent.TIMER_COMPLETE, deleteMe);             rt.start();         }         private function deleteMe(event:TimerEvent)         {             parent.removeChild(this);             delete this;         }         private function fadeMe(event:TimerEvent):void         {             this.alpha -= 0.01;         }     } }
Attached Files
File Type: zip as3_self_deleting_class.zip (5.4 KB, 311 views)
Mazoonist is offline   Reply With Quote
Old 07-11-2007, 03:05 AM   #4
Mazoonist
Site Contributor
 
Mazoonist's Avatar
 
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist
Default

I should say that I'm a real newb at programming classes. Just so's you don't think I'm trying to come off as some kind of expert. I'm beginning to understand the language of classes--I have yet to really understand any techniques or strategies. When I jump in and help someone out it's so that I can help myself learn, too. Sometimes it even backfires! (but hopefully I don't wind up annoying people). Just thought I'd clarify that.
Mazoonist is offline   Reply With Quote
Old 07-11-2007, 03:10 AM   #5
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,140
Default

no worries, bro. and your code looks good
__________________
trace("Good bye Flash.") Log.i(TAG, "Hello Droid");
Flash Gordon is offline   Reply With Quote
Old 07-11-2007, 05:01 PM   #6
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

This line shouldn't be needed. In fact, a delete call on "this" probably won't work anyway.

ActionScript Code:
delete this;

For the record, I recommend having SelfDelete send out an event when it is finished. Then your code in the main FLA where it was created can remove it from the display list and set its reference to null.
__________________
Josh Tynjala | Feathers
dr_zeus 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
Movie Clip in a movie clip? JetMonkeyUpload ActionScript 1.0 (and below) 2 04-03-2006 05:06 PM
cannot set/get properties on class instance - why? kracko ActionScript 2.0 10 08-07-2005 08:26 PM
Odd ... a movie clip w/ 4 stop()'s loops endlessly ... any advice? goToAndFix Simple Stuff (Newbies) 5 08-07-2005 04:33 PM
Detecting collision of 2 movie clips problem talie ActionScript 2.0 0 07-22-2005 06:07 AM
remove movie clip bimal ActionScript 1.0 (and below) 1 04-16-2003 07:31 PM


All times are GMT. The time now is 06:51 AM.

///
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.