Well, you can't have ObjectTracer cast to A or B so it's not going to be
exactly what you want.

But if the API were made to accept Object in the relevant places, then
you could do something like this:


package com.mycompany
{

import flash.util.Proxy;
import flash.util.flash_proxy;

use namespace flash_proxy;

public dynamic class ObjectTracer extends Proxy
{
    private var _instance:Object;

    public function ObjectTracer(o:Object)
    {
        super();
        _instance = o;
    }

    override flash_proxy function getProperty(name:*):*
    {
        trace("getProperty: " + name);
        return _instance[name];
    }

    override flash_proxy function setProperty(name:*, value:*):void
    {
        trace("setProperty: " + name + ", value=" + value);
        _instance[name] = value;
    }

    override flash_proxy function callProperty(name:*, ...rest:Array):*
    {
        trace("callProperty: " + name);
        return _instance[name].apply(_item, rest);
    }

    // etc... See ASDoc for rest of methods from Proxy that can be
overridden...

}

}




-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Vadim Melnik
Sent: Thursday, April 20, 2006 4:40 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How to override type cast operator @ runtime?

Thanks for information, sorry it was incorrect question, it was not
related to ObjectProxy.

I wanted to create special object wrapper, overriding flash.util.Proxy
methods and forwarding all calls to inner object, something like
ObjectProxy does. But instead ObjectProxy it will only trace
methods/properties/fields calls. It would be useful for object tracing
at runtime and for object profiling - without modifing object code, just
replace original object with object instance wrapped with ObjectTracer,
e.g.:


var a:A = A(new ObjectTracer(new A()));
var b:B = B(new ObjectTracer(new B()));

a.doSomething(); // ObjectTracer catch callProperty and trace it
b.prop1 = 123; // ObjectTracer traces b property set to 123, etc


Imagine some runtime or framework class you want to investigate or
profile, but there is no source code for this class. By replacing
original instance with proxied one it would be possible to see all
method calls and property accesses at runtime with a little efforts.

It's going to provide the same functionality as COM's TraceHook
(http://www.sellsbrothers.com/tools/#tracehook). But sounds like it's
impossible with AS3.


--
Thanks,
Vadim Melnik.

--- In flexcoders@yahoogroups.com, "Peter Farland" <[EMAIL PROTECTED]>
wrote:
>
> ObjectProxy is a Flex specific subclass of Proxy for wrapping
anonymous
> Objects that are dynamic and can't be predictably made bindable to
> report property change events. It shouldn't be used to wrap typed
> objects like instances of B (see later). You can never cast
ObjectProxy
> to B... the as operator never throws class cast exceptions, it just
> returns null if the type isn't correct. If you _did_ happen to end
up in
> the situation that B was wrapped in an ObjectProxy then you'd have
to
> unwrap the instance:
>
> var b:B = B(ObjectProxy(o).object_proxy::object);
>
>
> ...but this would be unusual since for serialization purposes in
FDS we
> do not support typed objects being wrapped in ObjectProxy
instances and
> sent to the server.
>
> Instead you should add [Bindable] metadta to public class B
definition.
>
> If you somehow ended up with an ObjectProxy in the result from an
FDS
> RPC service (like RemoteObject), then it's likely that the
> makeObjectsBindable attribute was true on your service but the type
> wasn't registered correctly with a remote class alias. In this case
> you'd add [RemoteClass(alias="com.mycompany.B")] to your public
class B
> definition.
>
>
> -----Original Message-----
> From: flexcoders@yahoogroups.com
[mailto:[EMAIL PROTECTED] On
> Behalf Of Vadim Melnik
> Sent: Wednesday, April 19, 2006 6:09 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] How to override type cast operator @ runtime?
>
> Hi All,
>
> flash.util.Proxy/mx.utils.ObjectProxy classes allow us to override
> properties access, methods call etc. Is it possible to override
type
> cast operations at runtime, like IUnknown:QueryInterface in COM?
For
> example:
>
>
> public class B {}
>
> ...
>
> var o:* = new ObjectProxy(new B());
> var b:B = o as B;
> trace(b); // <- writes "null"
>    // but I am looking for solution to
>    // hook type cast operation as well
>    // in other words need in ActionScript 3
>    // "universal delegate"

> --
> Thanks,
> Vadim Melnik.
>
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ:
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links








--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to