Most recent blog posts

New website Trident Microsystems online!

By Ivo te Kiefte

Trident Microsystems is a leading force in the digital home entertainment market, delivering innovative semiconductor solutions for digital televisions and set-top boxes. By acquiring the NXP Semiconductors portfolio for TV-solutions and set-top boxes, Trident positions itself as a global leader in this market. With the acquisition of the portfolio, the Trident website needed to be [...]

TriMM has moved to CeeCee!

By Sjors Trimbach

As of October 26th we are located in our new office building at Moutlaan 25 in Enschede. After 15 years in our old building it’s a strange feeling to be moving to a new location, but we are getting so much more in return. With a suitable farewell of our old building we are settling in [...]

Content Delivery Network via TriMM!

By Marc Woesthuis

TriMM is the exclusive Level3 partner for Content Delivery services in the Netherlands, Belgium and Luxembourg. These services are added to our experience and knowledge in managing complex hostingsolutions. We achieve the best performance results by combining certain hosting techniques. Level3’s content delivery network (CDN), a worldwide network of servers, stores website content close to [...]

Philips Insights

By Tim Koster

Philips is not just about making great televisions; Philips is about changing lives. This is what Philips Corporate Communications wants to express through an online interactive magazine. In addition to newsletters sent out by e-mail, Philips aims at providing a more involving experience to its visitors by communicating corporate themes and stories online. When Philips [...]

How do we cope with Google Chrome

By Erik Mollink

Out of the blue, Google Chrome saw the light on September 2, and managed to receive a market share of 1% within the day. This is for a new browser a very remarkable achievement. Chrome was on that particular day the 3rd most used browser (on the Windows platform). Current market share Now, almost two [...]

Iterating properties creates unwanted side-effects

By Hans Wichman

Also known as: iterating properties causes getter setter to execute I was working on our AS2 logger today. In particular I was creating a setup where you could simply drop in a couple components in your fla and ‘tada’, you would have a reflecting logger at your disposal. I’ll go into the reflecting logger and [...]

Consuming webservices in Flash 8

By Hans Wichman

During a partial refactoring process of the Behrloo client system, one of the items on my list was the backend webservice result processing. Without going into a lot of detail how these services are wrapped, it suffices to say that somewhere in the application a couple of webservices are being initialized and utilized through the [...]

Iterating properties creates unwanted side-effects

By Hans Wichman.

Also known as:

  • iterating properties causes getter setter to execute
  • I was working on our AS2 logger today. In particular I was creating a setup where you could simply drop in a couple components in your fla and ‘tada’, you would have a reflecting logger at your disposal.

    I’ll go into the reflecting logger and component creation in another post, because what happened was that during a test run I ran into the dreaded 256 levels recursion problem.

    Some research indicated that the problem lay with getters and setters.

    Imagine you have a class:

    class TestClass {
        public function get id1 () {
            trace ("hello world");
        }
    
        public function id2() {
            trace ("goodbye world");
        }
    }
    

    Now do:

    _global.ASSetPropFlags(TestClass.prototype, null, 0, 7);
    for (var i:String in TestClass.prototype) {
        trace ("Property:"+i+" is function ? "+(TestClass.prototype[i] instanceof Function));
    }
    

    Ok, truth be told, you will not do this every day. In fact building a reflection package is probably the only time this issue shows up. However I like to document stuff for posterity’s sake, so here we are.

    Executing the code above will show something like:
    hello world
    Property:id1 is function ? false
    Property:id2 is function ? true
    Property:__get__id1 is function ? true
    Property:__proto__ is function ? false
    Property:constructor is function ? true

    The _global.ASSetPropFlags is used to unprotect all the prototypes properties, in order to force them to show up. In a real situation, you should always make sure you keep track of the original settings of an object’s properties and revert the object back to those settings after you are done with it.

    Anyway what is really interesting is that testing the id1 property to see whether it is a function or not, causes the underlying method (the ‘get’ method) to execute.

    Luckily I never use getters and setters. But other people do. This is not to say that getters and setters are bad, just that I ran into a situation which I hadn’t anticipated :) .

    In most situation this will not cause a problem either, but you never know. The getter might go into a recursive loop if no parameters are passed. A class might update it’s properties unintentionally, who knows? I don’t. I do know that if those side effects do happen, you will lose hours of precious time bughunting.

    So how to circumvent these special properties of woe?
    If you look closely at the output again, you’ll see something like __get__id1 in there as well.
    These kind of methods will only be created by flash if you use getters and setters.

    So how can you detect if obj[i] refers to a getter/setter and should not be executed?

    Test for the existence of __set__i and __get__i.

    As the saying goes, you’ll find the solution in the last place you look.

    More information on ASSetPropFlags:
    http://objectpainters.com/blog/2007/06/21/assetpropflags-explained/

    Tags: , , , ,


    Comment: