简体   繁体   中英

Removing a movieclip by clicking a button within the movieclip I want to remove

I am trying to remove a movieclip (which has a AS Linkage to another class) by clicking on a button which is inside the same clip that I want to remove. I have asked a lot of people about this, and they seem to don't have a clue on how to do it. AS3 isn't exactly my cup of tea, so I couldn't find a way myself.

Here's what my (bad) code looks like for now:

public class PageWestmount extends MovieClip{
    // PROPRIÉTÉS
    // -----------------------------------------------------
    private var _XMLURLLoader:URLLoader = new URLLoader(); // object pour charger cibler l'emplacement du XML à charger                                             
    private var _requete:URLRequest; // init le chemin d'accès vers l'emplacement du XML
    private var _source:String; // init source du XML à charger
    private var _alimentation:Boolean;
    private var _hebergement:Boolean;
    private var _vestimentaire:Boolean;
    private var _video:Boolean;
    private var _photos:Boolean;
    private var _aide:Boolean;
    private var listePoints:Array;
    private var _XMLData:XML;
    var aide:pageAide= new pageAide();
    var video:Videos= new Videos();
    var photos:SrcPhotos= new SrcPhotos();

    // CONSTRUCTOR
    // -----------------------------------------------------
    public function PageWestmount(){
        addEventListener(Event.ADDED_TO_STAGE, init); 
        pageAide_mc.fermerAide_mc.addEventListener(MouseEvent.CLICK, removeAide);
        myVideoPlayer.fermerVideo_mc.addEventListener(MouseEvent.CLICK, removeVideo);
        compPhotos_mc.fermerPhotos_mc.addEventListener(MouseEvent.CLICK, removePhotos);
    }// end constructor

And here are the functions for removing the clips from the stage:

    private function removeAide(e:MouseEvent):void {
        removeChild(aide);
    }

    private function removeVideo(e:MouseEvent):void {
        removeChild(video);
    }

    private function removePhotos(e:MouseEvent):void {
        removeChild(photos);
    }

You can't just say removeChild(aide) , unless the 'removeChild' statement is on the parent's class and you're really trying to remove ITS child. Otherwise you have to put the proper lineage, of the object you're trying to remove, into the ( ). So if 'aide' is a child of 'fermerAide_mc' and if the removeChild statement is also on 'fermerAide_mc' then you CAN say removeChild(aide) . But if the removeChild statement is on 'pageAide_mc', which is the parent of 'fermerAide_mc' you'd have to say removeChild(fermerAide_mc.aide) . if the removeChild statement is on the parent of 'pageAide_mc', you'd say removeChild(pageAide_mc.fermerAide_mc.aide)

That's not too hard to understand, is it?

What if the 'removeChild' code in on the very object (aide) that you want to remove? Then you'd say MovieClip(parent).removeChild(aide) or MovieClip(parent).removeChild(this) . Remember, of course, that we're not talking about putting code directly on objects in the timeline. You always put Actionscript 3.0 code in the classes that control those objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM