Well, consider how an object can be manipulated.

var myObject:Object = new Object();
myObject.foo = "bar";

or

var myObject:Object = new Object();
myObject["foo"] = "bar";

Those are equivalent syntaxes. Everything basically inherits from Object, so this is valid syntax throughout, including your custom classes. Basically, you are accessing (and apparently creating) properties on the fly, with no type checking, and no compiler validation as to whether the property being accessed actually exists.

You can see a bit more of this if you consider the XML class:

var myXML:XML = new XML();
myXML.foo = "bar";

In this case, foo is not a valid property of the XML class, so the compiler spits out an error. However, if you do this:

var myXML:XML = new XML();
myXML["foo"] = "bar";

the compiler happily allows it, and a trace on myXML.foo reveals the value "bar".

One more thing, the LoadVars class takes advantage of the fact that the class is just a collection of properties. It allows for the arbitrary addition of properties using both syntaxes:

var myLV:LoadVars = new LoadVars();
myLV.foo = "bar";
myLV["baz"] -= "quux";
myLV.sendAndLoad("foo.jsp");

In many respects, LoadVars is doing what you want to do with your Session class.

Fun, eh!

Regarding number 2, that is what getters and setters are normally for. With arbitrary properties, someone correct me if I am wrong, but I don't think there is a way of intercepting them all, just specific ones that you have defined.

Nathan
http://www.nathanderksen.com


On Dec 30, 2005, at 9:55 AM, g.wygonik wrote:

lol - indeed. :-)

i'm just trying to look at possible "issues" that may come up later
on... but this scenario brings up two follow-up questions/concerns:

1 - the fact that Flash (AS2) will happily turn a class into an
associative array without any sort of warning. if a coder comes in and
uses session["foo"], it will work with no errors thrown. can i catch
this somehow? should they use this syntax throughout their modules, it
will work with no problems, but won't be "correct".

2 - can i somehow catch items being added to the class via the
ass-array method and properly add them to the Items array instead of
the root class? in other words, say a user does use the session["foo"]
method. can i intercept that call, add the item/value to the Items
array and remove it from the class? i thought about some sort of
watch, but i wouldn't know what to watch in this case...

while i'm going to be setting up a proper API for them to use, in a
way this conversation is over from a "real world" standpoint. but i'd
like to figure this out from a theoretical standpoint now.

g.

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to