I have a class member in an ActionScript 3 class that looks something like this:
private var m_myvect :Vector.<MyType> = new <MyType>[];
I’m exposing it through a getter, like this:
public function get mydata() :Vector.<MyType>
Which doesn’t help when I use it like this:
for (var o:Object in inst.mydata)
{
...
}
… because the type of o is not MyType, but Number instead, because it enumerates the vector indices instead of the data.
How would I expose only the data within the vector in a way which:
- Allows me to use
for(a in b)syntax - Does not expose the data in a way which allows it to be modified?
The only way to expose data that stops it from being modified (i.e. adding/removing items from the Vector, or changing the data in MyType) is to do it through functions on the parent object (that holds the Vector).
e.g.