[Laszlo-dev] Fwd: interesting introspection API for AS3

Donald Anderson dda at ddanderson.com
Mon Feb 11 08:53:58 PST 2008


Yes, I would think it would be easy - I'll try it now.

- Don

On Feb 11, 2008, at 11:18 AM, P T Withington wrote:

> Why not have the swf9 compiler do that, so we can have the source at  
> least be right?  Don it shouldn't be too hard to do that should it?   
> Can't you just make the getter for the public attribute always  
> return 'true'?
>
> On Feb 11, 2008, at 9:50, "Henry Minsky" <henry.minsky at gmail.com>  
> wrote:
>
>> Well, just for now, how about if I declare the instance vars in  my
>> swf9-specific branches of  LFC  files as public, to aid in
>> making a debugger for swf9,  and when we
>> merge them back with their original .lzs files, we can figure out how
>> to scope them?
>>
>>
>>
>>
>> On Mon, Feb 11, 2008 at 9:06 AM, P T Withington <ptw at pobox.com>  
>> wrote:
>>> I think namespace is the way to go.  The question is whether to do  
>>> it
>>> by hand or in the compiler.  One idea is that when compiling the  
>>> LFC,
>>> everything listed as public is in the lzxapplication namespace and
>>> everything else is in the lfc namespace.  Everything is public, just
>>> in different namespaces.
>>>
>>> I don't know how it is in AS3, but in JS2, a package is just a way  
>>> of
>>> creating a pair of namespaces: public and private.  So I don't see  
>>> why
>>> you couldn't do the same thing with explicit namespaces.
>>>
>>>
>>>
>>> On 2008-02-11, at 08:44 EST, Donald Anderson wrote:
>>>
>>>> I'd hate to change the visibility in the source, someday our js2doc
>>>> will want to take full advantage of it, and it's just the right
>>>> thing to do.
>>>>
>>>> One alternative is to have the script compiler strip private, and
>>>> add public,
>>>> for all vars when compiling in debug mode.  That would be at a risk
>>>> of getting
>>>> a different behavior (seems unlikely, would require some bad coding
>>>> in the LFC).
>>>>
>>>> Maybe there's some way to leverage namespaces to solve this?
>>>>
>>>>
>>>> On Feb 11, 2008, at 2:50 AM, Henry Minsky wrote:
>>>>
>>>>> I found out the describeType() function has this restriction:
>>>>>
>>>>> Note: describeType() only shows public properties and methods, and
>>>>> will not show properties and methods that are private, package
>>>>> internal or in custom namespaces.
>>>>>
>>>>>
>>>>> So if we want our debugger to really work nicely, I guess we  
>>>>> have to
>>>>> declare all variables as public on the LFC obejcts...
>>>>>
>>>>>
>>>>>
>>>>> ---------- Forwarded message ----------
>>>>> From: Henry Minsky <henry.minsky at gmail.com>
>>>>> Date: Tue, Nov 15, 2005 at 2:16 PM
>>>>> Subject: interesting introspection API for AS3
>>>>> To: Platform Team <platform-team at laszlosystems.com>
>>>>>
>>>>>
>>>>>
>>>>> So they have an API for inspecting a sealed class. Haven't seen if
>>>>> there is any API for modifying it at runtime though (I am guessing
>>>>> not)
>>>>>
>>>>>
>>>>> Using the introspection API
>>>>>
>>>>> If you want to list all the public properties and methods of a
>>>>> non-dynamic (or sealed) class or class instance, use the
>>>>> describeType() method and parse the results using the E4X API. The
>>>>> describeType() method is in the flash.util package. The method's  
>>>>> only
>>>>> parameter is the object that you want to introspect. You can  
>>>>> pass it
>>>>> any ActionScript value, including all available ActionScript types
>>>>> such as object instances, primitive types such as uint, and class
>>>>> objects. The return value of the describeType() method is an E4X  
>>>>> XML
>>>>> object containing an XML description of the object's type.
>>>>>
>>>>> The following example instrospects the Button control and prints  
>>>>> the
>>>>> details to TextArea controls:
>>>>> <?xml version="1.0"?>
>>>>> <mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml"
>>>>> creationComplete="getDetails()">
>>>>>
>>>>>
>>>>> <mx:Script>
>>>>> <![CDATA[
>>>>> import flash.util.*;
>>>>>
>>>>> public function getDetails():Void {
>>>>> // Get the Button control's E4X XML object description:
>>>>>
>>>>> var classInfo:XML = describeType(button1);
>>>>>
>>>>> // Dump the entire E4X XML object into ta2:
>>>>> ta2.text = classInfo.toString();
>>>>>
>>>>> // List the class name:
>>>>>
>>>>> ta1.text = "Class " + classInfo. at name.toString() + "\n";
>>>>>
>>>>> // List the object's variables, their values, and their types:
>>>>> for each (var v:XML in classInfo..variable) {
>>>>>
>>>>> ta1.text += "Variable " + v. at name + "=" + button1[v. at name] +
>>>>>
>>>>> " (" + v. at type + ")\n";
>>>>> }
>>>>>
>>>>> // List accessors as properties:
>>>>>
>>>>> for each (var a:XML in classInfo..accessor) {
>>>>> ta1.text += "Property " + a. at name + "=" + button1[a. at name] +
>>>>>
>>>>> " (" + a. at type +")\n";
>>>>>
>>>>> }
>>>>>
>>>>> // List the object's methods:
>>>>> for each (var m:XML in classInfo..method) {
>>>>> ta1.text += "Method " + m. at name + "():" + m. at returnType + "\n";
>>>>>
>>>>> }
>>>>> }
>>>>> ]]>
>>>>> </mx:Script>
>>>>>
>>>>> <mx:Button label="Submit" id="button1"/>
>>>>> <mx:TextArea id="ta1" width="400" height="200" />
>>>>>
>>>>> <mx:TextArea id="ta2" width="400" height="200" />
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Henry Minsky
>>>>> Software Architect
>>>>> hminsky at laszlosystems.com
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Henry Minsky
>>>>> Software Architect
>>>>> hminsky at laszlosystems.com
>>>>
>>>>
>>>> --
>>>>
>>>> Don Anderson
>>>> Java/C/C++, Berkeley DB, systems consultant
>>>>
>>>> voice: 617-547-7881
>>>> email: dda at ddanderson.com
>>>> www: http://www.ddanderson.com
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>> -- 
>> Henry Minsky
>> Software Architect
>> hminsky at laszlosystems.com


--

Don Anderson
Java/C/C++, Berkeley DB, systems consultant

voice: 617-547-7881
email: dda at ddanderson.com
www: http://www.ddanderson.com






More information about the Laszlo-dev mailing list