Skip to Content »

FlashApe » ReferenceLocator - store a reference to anything as a string

 ReferenceLocator - store a reference to anything as a string

  • July 14th, 2006
  • 4:16 pm

I was in a situation where i needed to refer to an instance of a Tween in a separate method than where it was created. The first two thoughts that come to mind are storing it as a var in the class, or attaching it to a property to an object(usually a dynamic property of a movieclip). That’s always bothered me a little cause its a hack…granted that’s the bread and butter of AS1, but there’s a reason people are moving away from that.

I dawned on me how many other times i need to store references somewhere for other things…for example, cases where I need to store a reference to the function returned from a Delegate.create() in order to delete it later or something.

So, i just whipped together this ReferenceLocator class (a little nod to ARP). basically you just pass an object to its addReference() method that contains two properties: referenceName and referenceTo. Optionally, you can add a method to the object named overwrite, and set it to true, and that will overwrite an existing reference with the same name. To get the object, you just pass its referenceName to the getReference() method. There’s also a deleteReference() method, which will delete the reference with the given name, optionally deleting the object as well.

You can read more about and download it from the downloads page.

2 People had this to say...

[…] A class to store and retrieve string references to any object. Good for storing references to the functions returned from Delegate.create(), or tweens, or anything at all. http://www.visible-form.com/blog/referencelocator-store-a-reference-to-anything-as-a-string/ PLAIN TEXT Actionscript: […]

Gravatar
  • rich
  • July 31st, 2006
  • 1:46 pm

yeah…so the more I’ve thought about this the more I realize this is pretty much just a Singleton replacement for the _global object, which a few extra methods.

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>