A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS 2.0 destructor ?

  1. #1
    .:|8^)\ if I only had a brain! gangelo's Avatar
    Join Date
    Oct 2002
    Location
    USA, Boonton, NJ
    Posts
    156

    AS 2.0 destructor ?

    I have a class I created that needs to have a "destructor" called when it is deleted. How can I accomplish this? I do not want to have to call a function to "cleanup" before performing delete myobject;

    Any ideas?

  2. #2
    Junior Member scudsucker's Avatar
    Join Date
    Feb 2003
    Location
    Cape Town, RSA
    Posts
    1,509
    Something like this? (pseudo-code)
    code:

    function deleteThis(obj) {
    trace("this is where you'd do the destructor call");
    delete obj;
    }

    Hariyemadzisawira nhaka yedu! Down the SCUD and win!
    I'm too lazy to read Private Messages.

  3. #3
    .:|8^)\ if I only had a brain! gangelo's Avatar
    Join Date
    Oct 2002
    Location
    USA, Boonton, NJ
    Posts
    156
    Originally posted by scudsucker
    Something like this? (pseudo-code)
    code:

    function deleteThis(obj) {
    trace("this is where you'd do the destructor call");
    delete obj;
    }

    scuds...you gotta read the post BEFORE you reply

    I do not want to have to call a function to clean up the object before I call delete myobject; In other words, when I do "delete myobject;" I want a member function within myobject to be called BEFORE the object is actually deleted. This would be a case where the object's destruction would act more like in a C++ class

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    This works.

    fla file
    var a:Myclass = new Myclass();

    .as file
    PHP Code:
    class Myclass {
        var 
    a:Myclass;
        public function 
    Myclass (){
            
    trace("Class is working");
            
    nowDestroy ();
        }
        
        private function 
    nowDestroy(){
            
    _root.onEnterFrame = function(){
                
    trace(_root.a);//is defined
                
    if(_root.!= undefined){
                    
    delete _root.onEnterFrame;
                    
    delete _root.a;
                    
    trace("_root.a: "+_root.a);//undefined
                
    }
            }
        }

    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    .:|8^)\ if I only had a brain! gangelo's Avatar
    Join Date
    Oct 2002
    Location
    USA, Boonton, NJ
    Posts
    156
    Originally posted by cancerinform
    This works.

    fla file
    var a:Myclass = new Myclass();

    .as file
    PHP Code:
    class Myclass {
        var 
    a:Myclass;
        public function 
    Myclass (){
            
    trace("Class is working");
            
    nowDestroy ();
        }
        
        private function 
    nowDestroy(){
            
    _root.onEnterFrame = function(){
                
    trace(_root.a);//is defined
                
    if(_root.!= undefined){
                    
    delete _root.onEnterFrame;
                    
    delete _root.a;
                    
    trace("_root.a: "+_root.a);//undefined
                
    }
            }
        }

    ty, I will give it a try

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center