0

Ok, here's a simple example of what I mean:

public class Blob extends MovieClip {

    public var gfx:BlobClip; //BlobClip is a MovieClip class in my assets library
    public var bCount:uint;

    //...

So gfx is the graphical representation of my Blob object.

I set up the mouse event to make the gfx clip clickable:

blob.gfx.addEventListener(MouseEvent.CLICK, blobClick); //blob is an instance of Blob

In the blobClick function I can of course access the gfx clip of blob using e.target.

function blobClick(e:MouseEvent) {
    trace("Target:"+e.target);
}

But I wish instead to refer to the blob object itself so that I may access the bCount property. How do I do this? :(

I figured I might have to use e.target.root or e.target.parent but these relate to display.

Any assistance in this matter would be greatly appreciated.

Drekinn
  • 33
  • 6

1 Answers1

0

I hope there are no typos... I did not run it into flash or flex...but this should give you what you need.

public class Blob extends MovieClip {

     public var gfx:BlobClip; //BlobClip is a MovieClip class in my assets library
     public var bCount:uint;

     ...

     // this is your contructor
     public function Blob()
     {

          super();
          // add reference here
          gfx.parentBlob = this;
     } 
     ....
}

Add the property 'parentBlob' inside BlobClip

class BlobClip extends MovieClip 
{
    ...
    public var parentBlob:Blob = null;
    ... 

    public function BlobClip()
    {
         super();
    }

}

Then in your event handler you can have something like this

function blobClick(e:MouseEvent) 
{
    var bClip:BlobClip = e.target as BlocbClip;

    // this is what you need...
    var blob:Blob      = bClip.parentBlob;

}
Adrian Pirvulescu
  • 4,308
  • 3
  • 30
  • 47
  • Ahh.. it seems `super()` is the keyword I was initially after. It might take me a while to get my head around this example though. Thanks, @Adrian, for your help in this matter. :) – Drekinn Sep 24 '14 at 14:16