  | |  | tree data structure | tree data structure 2004-03-11 - By Jim Cheng
Back Millie Niss on eathlink wrote:
> I need a tree data structure (probably augmented to have a linked list of > its leaves) for a program I am writing to generate poetry. I am planning to > write a tree class, but I haven'ty used AS 2.0 much (I have done some C++, > Java, etc. and a lot of the old Actionscript). Are there any pitfalls I > should avoid? I gather objects are passed by refernce, so if I want a > reference to the same object (not a cloned object) I can just say > obj2:Object = obj1. Can I treat everything as type object and cast it when > I need to as in C++, or do I need to keep referring to things by their > actual class, instead of a parent class that contains all the types I am > dealing with?
Hmm, with respect to object types in AS 2, you can cast objects into different types as well as create non-type checked references. In practice, AS 2 only cares about type at compile-time. At run-time, so long the member variable or method is there, you're fine.
Here's some tricks you can play:
<code>
// Create an instance of Foo var fooInstance:Foo = new Foo();
// Cast it into an instance of Bar var barInstance:Bar = Bar(foo);
// This won't work though... var barInstance:Bar = foo;
// This is fine, since k is untyped var k = 'some string'; k = fooInstance;
</code>
Regards, Jim
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Supported by Fig Leaf Software =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- Be sure to check the archives and the wiki: http://chattyfig.figleaf.com/ =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:106630 =-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe send a blank e-mail to: Normal Mode: flashcoders-unsubscribe@(protected) Digest Mode: flashcoders-digest-unsubscrive@(protected)
Earn $52 per hosting referral at Lunarpages.
|
|
 |