3 Replies Latest reply on Oct 11, 2010 1:39 AM by FlexMatt

    Script to insert an existing Rich symbol throws error

    FlexMatt Level 1

      I have an existing Rich Symbol called RSymbol. Now I write a script to place RSymbol into a certain layer which create. The problem is, that everytime i import a symbol like this with


      fw.getDocumentDOM().importFile(fw.appSymbolLibrariesDir+"RSymbol.graphic.png", {left:136, top:108, right:136, bottom:108}, false, 0, false);


      Fw doesnt import the properties for this symbol and throws an error "Component graphic or script edited An error occured"


      I also tried to put the rich symbol in the appSwfCommandsDir but it didnt work either. I guess the problem could be that the RSymbol isnt in the Common Library folder. appSymbolLibrariesDir doesnt point to the common library folder but to some other folder (Adobe Fireworks CS5\Configuration\Libraries).


      I also tried to use fw.getDocumentDOM().importFile(fw.appSettingsDir+"/Common Library/... but it doesnt work either.


      I want to use this script in a panel so I cant hard code the absolute path.


      Any suggestions how to import a rich symbol and make the rich properties available?


      Thanks a lot!

        • 1. Re: Script to insert an existing Rich symbol throws error
          FlexMatt Level 1

          oh and by the way importing a rich symbol from fw.userSymbolLibrariesDir doesnt work either. Since this property doesnt point to the common library (which I would have expected)


          So is there a hidden property which the FWAPI Inspector doesnt find or is it just not possible to import rich symbols via a script???


          This is the last hurdle in my panel code, if you guys can help me this would be awesome



          • 2. Re: Script to insert an existing Rich symbol throws error
            John Dunning Level 1

            Sadly, I don't think there's any way to programmatically insert a rich symbol while maintaining its "richness".  I tried and failed to do that in my QuickFire extension: http://johndunning.com/fireworks/about/QuickFire


            The best I could do was to insert the symbol in a way that if you had already dragged that symbol from the common library into the document, the new instance would still show something in the symbol properties panel.  Here's the code that QuickFire uses to insert symbols:


            function insertSymbol(
                 var dom = fw.getDocumentDOM();
                 var middleX = Math.round(dom.width / 2);
                 var middleY = Math.round(dom.height / 2);

                 try {
                           // first assume the symbol is already in the library and try to
                           // insert an instance.  there doesn't seem to be an API to list
                           // the symbols in the document, so we just have to try it.
                      dom.insertSymbolAt(inSymbolName, {
                           x: middleX,
                           y: middleY
                 } catch (exception) {
                           // replace the user or app JS directory path tokens with the
                           // actual path, so that importSymbol will find it below
                      inPath = inPath.replace(/^:U:/, k.UserSymbolsPath).replace(/^:A:/, k.AppSymbolsPath);
                           // the symbol isn't in the document yet, so import it.  we use
                           // importFile instead of importSymbol because the former seems
                           // to preserve some magic that allows you to turn it back into a
                           // rich symbol if you later drag the same symbol from the Common
                           // Library into the doc and replace existing instances.
                      dom.importFile(inPath, {
                           left: middleX,
                           right: middleX,
                           top: middleY,
                           bottom: middleY
                      }, true);

            // this is a failed attempt to import a rich symbol.
                           // the jsf filename doesn't include the .graphic bit
                      var jsfPath = inPath.replace(/\.(graphic|animation|button)\.png$/, ".jsf");
                      if (Files.exists(jsfPath)) {
                                // to change the opCode, so that the rich symbol's jsf file
                                // will give it the default values, we need to create a proxy
                                // Widget object.  but first save off the actual Widget.
                           var _Widget = Widget;
                           Widget = {
                                     // we want this to be opCode 1, which will set the symbol's
                                     // default values
                                opCode: 1,
                                     // the symbol we just imported is Widget.elem
                                elem: fw.selection[0],
                                propString: _Widget.propString,
                                     // pass these method calls on to the real Widget
                                GetObjectByName: function()
                                     return _Widget.GetObjectByName.apply(_Widget, Array.prototype.slice.call(arguments, 0));
                                isWidgetSelected: function()
                                     return _Widget.isWidgetSelected.apply(_Widget, Array.prototype.slice.call(arguments, 0));
                                UpdateWidget: function()
                                     return _Widget.isWidgetSelected.apply(_Widget, Array.prototype.slice.call(arguments, 0));
                                // reset the global to the real Widget object
                           Widget = _Widget;


            Hope that helps.

            1 person found this helpful
            • 3. Re: Script to insert an existing Rich symbol throws error
              FlexMatt Level 1

              Hi John,


              thanks a lot for the advise and the example. Though I think I will make my customer use a template file in which document library the symbol is already imported. I hope that works.


              I guess I have to file a bug/feature-request for this rich symbol importing issue