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.
[…] 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: […]