Object Proxy (cont)

I ran across the topic again, and again this week, and I haven’t even been working in Flex.  It’s been all Java this week.  I was cruising through the blogs of the European Union, and found this comment:

“Yep already… I fixed the annoying “Lazy Loading”-issue. I found a little hack and it goes something this:

  1. Store openDuration and closeDuration;
  2. Set openDuration and closeDuration to 0;
  3. Call open and close methods;
  4. Restore openDuration and closeDuration;
  5. TADA… lazy loading be gone….. “

http://labs.flexcoders.nl/?cat=3

Is it possible that the standard use of Delayed Instantiation of Objects, is emerging as an Anti-Pattern, as programmers worldwide come up with various solutions and workarounds to make the objects behave as procedural Objects would?

And at the same time, other programmers are adding additional Proxy wrappers, to achieve the effect they need.  Utilizing the Double Proxy Pattern, the first access to the object would release the inner proxy, and fire off a request to fill in the proxy with “real” data.  Hopefully, by the next time the object is accessed, it will be populated.  This is related to the re-wrapping with ObjectProxy which I have seen.

——

  Earler this week, a colleague was putting together a dashboard application view, and had a coldfusion remote service all wired up in ColdSpring, and was at the point of getting the data back in the ResultEvent of the Service Delegate, and was getting strange results.  The ResultEvent.result was an ObjectProxy, or nothing.  He was not getting a list of data for his view to bind to.  He was returning an array of some type, but the remote object declared it was returning type “any”.  Well, when we fired up Charles, and looked at the AMF result coming from the Coldfusion server, the type was a custom coldfusion recordset.  So, he changed the declaration of the return type to “Array”, and lo and behold, while observing in Charles, we saw that the  AMF return type was ArrayCollection.  And the rest of his code worked, and the dashboard element filled up, because the data was in a format that Flex recognized.  I don’t know exactly what this tells me, except that the return type declaration in Coldfusion is important.  As is the RemoteObject type meta tag in the Flex Value Object declaration.

  He did not try another test, wrapping the result in ObjectProxy to see if that would have taken care of the problem.  I don’t know that it would *solve* it, but it would probably yield different results.

  And then I am reminded of this post:

“Accessing proxied object

Under some circumstances Flex wraps object with special mx.utils.ObjectProxy wrapper class. Documentation describes special object_proxy “object” property containing reference to real object. But accessing this property at runtime always returns “null”, althought this property is visible in debuger watch window with “package” icon. Code below demonstrates the problem, and shows “Real object: null” message:

 import mx.utils.ObjectProxy;
 import mx.controls.Alert;
 …
 var o1:Object = { f1:”aaa”, f2:123 };
 var o2:Object = new ObjectProxy(o1);
 var o3:Object = ObjectProxy(o2).object;
 Alert.show(“Real object: “+o3);
Matt Chotin pointed me to the solution. It’s special namespaced property and need in special code handling. So updated example listed below:

 import mx.utils.ObjectProxy;
 import mx.utils.object_proxy;
 import mx.controls.Alert;
 …
 var o1:Object = { f1:”aaa”, f2:123 };
 var o2:Object = new ObjectProxy(o1);
 var o3:Object = ObjectProxy(o2).object_proxy::object;
 Alert.show(“Real object: “+o3);”

from http://www.docsultant.com/site2/articles/flex_internals.html

(to be continued)

Advertisements

One Response to Object Proxy (cont)

  1. Ormus says:

    That was awesome, mate.

    [Bindable] private var myData:ArrayCollection;
    [Bindable] private var myNewData:ArrayCollection;
    while (i < myData.source.length){
    myNewData.addItem(myData[i].object_proxy::object);
    i++;
    }

    if you know what i meant….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: