Skip navigation
Currently Being Moderated

Script to insert an existing Rich symbol throws error

Oct 7, 2010 7:28 AM

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.graph ic.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!

 
Replies
  • Currently Being Moderated
    Oct 10, 2010 9:21 PM   in reply to FlexMatt

    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(
         inSymbolName,
         inPath)
    {
         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));
                        }
                   };
                   
                   fw.runScript(jsfPath);
                   
                        // reset the global to the real Widget object
                   Widget = _Widget;
              }
    */
         }
    }

     

    Hope that helps.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points