-
.:|8^)\ if I only had a brain!
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?
-
Junior Member
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.
-
.:|8^)\ if I only had a brain!
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
-
Senior Member
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.a != 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. -
-
.:|8^)\ if I only had a brain!
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.a != 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|