Many people who work with Director, use also Flash. Some of those who use Flash, write extensions for it. And definitely a lot of people who write extensions for Flash meet with specific problems, one of which is the matter of this article. What is the problem in short? If we try to create a custom dialog box, using the JSFL function,
fl.getDocumentDOM().xmlPanel( "the path to your dialogue definition file" );
and we want that our dialogue has a colorpicker with a defined by us default colour value, we see that this turns out to be impossible.
According to the Macromedia/Adobe documentation the following definition:
<?xml version="1.0"?> <dialog id="demo" title="ColorPicker Test" buttons="accept, cancel"> <colorchip id="color1" value="#FF6600"/> <button id="dummy" label="Dummy"/> </dialog>
must return this result:
We receive the following result, instead:
It is obvious that the attribute “value” has no effect on the <colorchip> element. How to solve this problem? How to set the colorpicker default value?
The solution came to me by accident, after a chain of actions caused by desperation. Initially I decided to set the colorchip value explicitly with the help of a defined in the dialog javascript. I added the <script> section (where I inserted the javascript code into), as well as the oncreate attribute in the <colorchip> element.
<?xml version="1.0"?> <dialog id="demo" title="ColorPicker Test" buttons="accept, cancel"> <colorchip id="color1" value="#FF6600" oncreate ="init()"/> <button id="dummy" label="Dummy"/> <script> function init(){ fl.xmlui.set( "color1", "#FF6600" ); } </script> </dialog>
The result was discouraging once again.
After certain meditation, I decided that it might be necessary the javascript code to be executed with some delay, after the full initialization of the <colorchip> element. That is why I moved the oncreate attribute to the next UI element in the dialog:
<?xml version="1.0"?> <dialog id="demo" title="ColorPicker Test" buttons="accept, cancel"> <colorchip id="color1" value="#FF6600"/> <button id="dummy" label="Dummy" oncreate ="init()"/> <script> function init(){ fl.xmlui.set( "color1", "#FF6600" ); } </script> </dialog>
Now the result is as expected:
By good fortune, in my specific case this next UI element turned out to be a button. Later I found out that the oncreate event does not happen with the initialization of all of the UI elements. Up to now I have ascertained that it happens only when <button> and <menulist> elements are initialized.
Very interesting, this will be useful for some of my future JSFL scripts!
Do you know by anychance if, within a tag… can you get data from other JSFL scripts? Like, basically populate the defaults with whatever was last used by the user (or loaded from a file with FLfile even)?
Thanks for the article!