Split Properties Bug and Workaround

Found a really odd and nasty MX04 bug today. I had a script that attempted to set the property of a behavior of a sprite externally, like sprite(1).pMyProp = 7. What was happening was that it appeared to change externally (put sprite(1).pMyProp), but the code in the behavior saw the old pMyProp value, not the new one. So in the behavior, I had two different values for pMyProp and sprite(me.spriteNum).pMyProp. This was the only behavior of the sprite.
What I discovered, thanks to JHT at Macromedia, was that Flash sprites in MX04 have the ability to have variables that are directly addressable. So sprite(1).pMyProp = 7 was creating a Flash variable in the Flash movie that had a value of 7. So I had a Flash variable and a sprite behavior property of the same name.
There are plenty of fixes for this. One would be to have setMyProp() and getMyProp() fuctions in the behavior and only set them this way. That’s a very object-oriented approach. You could also refer to the property externally via the scriptInstanceList: sprite(1).scriptInstanceList[1].pMyProp = 7.
This bug could very well break old Shockwave movies, so be on the lookout.

Posted on March 2, 2004 at 4:01 pm by Gary Rosenzweig · Permalink
In: General