Highlighted

Script object in fragment not working?

andygoldstein

14-11-2008

I have a fragment that contains a script object and a text field. The text field's initialize event handler calls a method in my fragment's script object. Everything works fine in preview mode of the fragment.



When I create a new file and use the fragment in that file, the initialize event handler in my fragment is invoked just fine, but the method I'm trying to call in the script object in the fragment never fires. What I have looks like this:



File

- fragment



Fragment

- script object "Foo"

- someMethod()

- xfa.host.messageBox("Foo");

- text field::initialize

- xfa.host.messageBox('hello');

- Foo.someMethod();



When I preview the fragment, I get "hello" and "Foo" message boxes.



When I preview the file, I only get the "hello" message box.



Is what I'm trying to do possible?



Thanks,

Andy

Replies

Highlighted

pguerett

14-11-2008

When calling the script object that is embedded in the fragment you have to path specifically to that object. The scriptobjectName.method is not enough to find what you want. You would need FragmentName.ScriptObjectName.Method()



I tried it here and it worked.



You may want to use a script Fragment instead of using an embedded script object on a fragment. The script fragment would run in the form root context and would behave like you are expecting.
Highlighted

andygoldstein

14-11-2008

Hi Paul,



Thanks for the quick response. For the script fragment approach, would I insert the script fragment into the file, or can I put it in my content fragment?



Thanks,

Andy
Highlighted

pguerett

14-11-2008

Put it in the file so that it is at the root of the file. It will act like any other fragment (the designer cannot edit it unless they have access to the fragment source) and it will be resolved when the form is rendered, so any updates are picked up right away.