Wednesday, July 30, 2008

'AG_E_RUNTIME_METHOD : Begin' error when starting a storyboard

Before starting animation, always make sure that animation objects and objects participating in the animation are added to the application's main object tree.
var myControl = plugIn.content.createFromXaml(a.loader.GetResponseText(part), true);
myControl.findName('myStoryBoard').Begin();
parentCanvas.children.add(myControl);

On Silverlight 1, this code will result an (infamous) error: AG_E_RUNTIME_METHOD : Begin

The solution is simple, add the created object first to main object tree and then start the animation:
var myControl = plugIn.content.createFromXaml(a.loader.GetResponseText(part), true);
parentCanvas.children.add(myControl);
myControl.findName('myStoryBoard').Begin();

This is obvious when looking to simple code like this, but in a bigger application it might not look so.
It's 'interesting' that in Silverlight 2.0 this error does not appear.

No comments: