views:

289

answers:

3

So I know as3 doesn't have pointers, but I thought there might be a way to use object variables as pointers.

Right now I'm relying on passing a function that gets the get function, it's not a very elegant solution something like this:

myvar = function():int{return objectName.getVarValue};

The other option would be to change all the gets and set methods into get and set functions, or add these in addition to. I could also create a linking class that just stores the name, but that that is just a bigger headache.

can anyone confirm for me that there really isn't a way to get the up-to-date values of an object's variable without without doing anything more complicated than this?


There is essentially three parties involved, almost like an MVC. I one object is the controller, that tells which value of the "view" to be matched with whichever datakey. The View is kind of dumb, and so is the data/model so everything is done through the controller and in a sequence where these events overlap. So I'm delegating the data-grabbing to the datakey, by defining at the beginning all the different parameters, and later I can just call the update and select the datakeys and they grab the data. right now I have the constructor linked to the value through a function I'm creating like this

onUpdate:function():int{return objectName.getVarValue};

it's a bit more complex than that, but that's the gist of it. In Flex you can do data binding, but that's a flex thing and not AS3, and it's not exactly a pointer either.

I wish as3 could just do pointers, maybe in as4? I thought there might be a way to retrieve the getter as a function that I didn't know of.

A: 

Why not just hit up the object for the value? Why the need to store in another variable unless you want a specific value at a specific time?

UltimateBrent
A: 

a way to get the up-to-date values of an object's variable -Daniel

It's not real clear what you are looking to accomplish. Maybe if you can explain why doesn't simply doing this meet your requirements?

myvar = return objectName.getVarValue;
AaronLS
A: 

I would just pass the object itself, since the reference behaves most like a pointer. You can cook up your own data binding using dynamic properties. When you want to wire up your view to the data model, the controller creates a data binding with the data source object, and the name of the property to bind on the data source, and the name of the property to bind on the view:

view.AddBinding(dataObjectName, "somePropertyOnObject", "propertyNameOnView");

You can store these in some sort of Binding class you create, and in each call to AddBinding, you add it to a collection, probably making sure no duplicates exist for a given "propertyNameOnView". When you need to respond to a property update event on the data object, you make the assignment like the below, except you'd grab the strings from your the Binding object, maybe iterating through the entire collection of Bindings to perform a full update of the view:

this["propertyNameOnView"] = dataObjectName["somePropertyOnObject"];

But more like this with a binding object:

someBinding.DestinationObject[someBinding.DestinationProperty] = 
  someBinding.DataSource[someBinding.SourceProperty];

You could even put this code directly in the Binding object itself exposed through an Update method so that you just call Update() on the particular binding, and it brings the data up from the data model's property to your view's property.

This is a little information on dynamic properties to get you started if you are not familiar with them: http://www.colettas.org/?p=17

AaronLS