PRIM ships with support for a new type of reference called Prim.REFERENCE_PATH. Unlike plain references, a reference path always uses path to determine its value and is never frozen. Although confusing at first, I have found myself using reference path in all sorts of cases. &
// create a prim reference path in global
// set value to mirror _level0._x
_global.createPrim ( Prim.REFERENCE | Prim.PATH , "my_x" , "_level0._x" )
trace ( _global.my_x ) // 0
_global.my_x = 30 // movie is shifted 30px horizontally
trace ( _level0._x ) // 30
trace ( _global.my_x ) // 30
_level0._x = 90
trace ( _global.my_x ) // 90
The key here is that every "get operation" retrieves the value of _level0._x by path and every "set operation" sets the value in the scope of the path property. Shifting _x around remotely is cool but there are far more practical uses.
// create a prim reference path in global
// set value to a path that has yet to be created
_global.createPrim ( Prim.REFERENCE | Prim.PATH , "mydog" , "_level0.dog" )
trace ( _global.mydog ) // undefined
_global.mydog = { a:23 , b:"Hello World" }
trace ( _level0.dog.a ) // 23
_level0.dog = new XML( "<hello/>" )
trace ( _global.mydog ) // <hello/>
_level0.createEmptyMovieClip( "dog" , 2000 )
trace ( _global.mydog.getDepth() ) // 2000
//global seems allot more useful now doesn't it ;)
Typically this would not be the case. As soon as you set the value of _global.mydog all association with _level0.dog is gone and changes to _level0.dog are irrelevant. The above case lets you bind 2 properties together based on path making them seemingly identical. Better still is the fact that you can chain many properties together so 5, 10, 15 properties can all point to a single value. This is especially useful in a class that needs to provide a local property yet is linked to a global property. If the property is modified in a class instance, the global property is modified transparently and changes are provided seamlessly to all other instances. Even methods of a class can be Reference Paths that execute on a different objects altogether yet seam local to the class.
PRIM Documentation
Cheers,
ted ;)
DIGG IT!
0 Responses to “ PowerSDK PRIM - Reference Path ”
Post a Comment