Ted Patrick - Demos & MAX @ Adobe Systems


Note: This is the personal blog of Ted Patrick. The opinions and statements voiced here are my own.



References by Path >> pathRef Library

DIGG IT!     0 Comments Published Thursday, February 26, 2004 at 9:44 AM .

Wouldn't it be nice to create a reference by path. Here is a solution in AS1.

Download

//via an object property
a = {}
a.x = 23
pathRef('x','_level0.a.x')

trace(x) //23
x = 45
trace(x) //45
trace(a.x) //45

//via a movieclip property
pathRef('x','_level0._x')
trace(x) //0
x = -100
trace(x) //-100
trace(_level0._x) //-100

Better still as a pathRef is always created by path so if you swap the object it is pointed at, the reference will still work. With pure references this would break.

a = {}
a.x = 23
pathRef('x','_level0.a.x')
trace(x)
//redefine a
a = function(){}
a.x = "I am a function now!"

trace(x) //I am a function now!

Too fun. This one has 1000's of uses from remote controlling objects to reference resilient classes.

As always send me any bugs or changes in the code.

Cheers,

ted ::)

0 Responses to “References by Path >> pathRef Library”

Post a Comment

Where to find me:

Ted on Twitter - @AdobeTed
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe


Latest

Lists

Links

Jobs

Flex Jobs
city, state, zip

Archives