It's not going to delete because somewhere else in your code you have a
reference to that object.  For example:

var myObj = new A();

myObj.destory(); // won't be deleted until myObj no longer points to the
class.

If you really have your heart set on following something a little more OOP,
try this.

class A
{
    public static var instance:A = new A();

    private function A()
    {
        // construct
    }

    public function destroy()
    {
        delete instance;
    }
}

a singleton that will destroy it's own reference.  Then the code is within
the class.  The problem now is that you're required to always reference this
class through the static class

A.instance.doSomething();
A.instance.destroy();

Flash is getting better (garbage collection model changes) with AS 3.0, but
for AS 2.0 you're stuck.

Tell me what you want to do in "destroy" and I"ll bet there's a better
solution that is still OOP.  If it's just to delete the object then there's
no reason to have the method.  Sorry.

Tyler

On 12/4/05, Alias <[EMAIL PROTECTED]> wrote:
>
> Hi Boon,
>
> Good luck with learning bytecode.
>
> However, I suspect that the reason your first delete statement doesn't
> work is because of the way flash's garbage collection works. When you
> call delete on an object, it is marked for deletion by the garbage
> collector. It uses reference counting to decide whether to actually
> delete something, so I suspect that if you try to delete an object
> from within itself, it most likely will not actually do so, until that
> object has finished up. I'd say you should probably always try to
> delete objects from outside of their own scope.
>
> It's likely that if this is indeed the case, the problem will look
> exactly the same at the bytecode level.
>
> Hope this sheds some light on your problem,
> Alias
> On 12/3/05, Boon Chew <[EMAIL PROTECTED]> wrote:
> >
> > Is there any tools or documentation out there that
> > will aid in learning actionscript bytecode?
> >
> > I ran into this the other day, and it seems like only
> > reading the bytecode can help me understand why it
> > doesn't work?
> >
> > class A
> > {
> >    function destroy()
> >    {
> >       delete this;  // doesn't delete itself
> >    }
> > }
> >
> > var a = new A();
> > delete a;  // delete works here
> >
> > - boon
> >
> >
> >
> > __________________________________
> > Start your day with Yahoo! - Make it your home page!
> > http://www.yahoo.com/r/hs
> > _______________________________________________
> > Flashcoders mailing list
> > Flashcoders@chattyfig.figleaf.com
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to