1 Reply Latest reply on Oct 18, 2009 7:58 PM by John Dunning

    AAAARGH! Flash panel to Fireworks communication

    Doug Hungarter

      This is making me CRAZY.

      I wrote a .jsf file to export pages to PSDs and it works fine.

      I then created a simple, custom Flash panel to allow for multiple export options.

      Now, when I try to execute the same function via MMExecute(), nothing happens.

      Is there something I'm missing about how Flash panels communicate with FW?

      Here is the actionscript if anyone cares to investigate...

       

      import mx.controls.ComboBox
      import mx.controls.Button

       

      Stage.scaleMode = "noScale";
      Stage.align = "TL";

       

      // Style the combo boxes
      set_objects.setStyle("color", "0x060606");
      set_effects.setStyle("color", "0x060606");
      set_vectors.setStyle("color", "0x060606");
      set_text.setStyle("color", "0x060606");

       

      set_objects.setStyle("fontFamily", "Lucida Grande");
      set_effects.setStyle("fontFamily", "Lucida Grande");
      set_vectors.setStyle("fontFamily", "Lucida Grande");
      set_text.setStyle("fontFamily", "Lucida Grande");

       

      set_objects.setStyle("fontSize", "11");
      set_effects.setStyle("fontSize", "11");
      set_vectors.setStyle("fontSize", "11");
      set_text.setStyle("fontSize", "11");

       

      set_objects.setStyle("textSelectedColor", "0x336699");
      set_effects.setStyle("textSelectedColor", "0x336699");
      set_vectors.setStyle("textSelectedColor", "0x336699");
      set_text.setStyle("textSelectedColor", "0x336699");

       

      set_objects.setStyle("themeColor", "0xC5D0DA");
      set_effects.setStyle("themeColor", "0xC5D0DA");
      set_vectors.setStyle("themeColor", "0xC5D0DA");
      set_text.setStyle("themeColor", "0xC5D0DA");

       

      // Get initial selection values to pass as defaults
      var set_objects_value:Number = 1;
      var set_effects_value:Number = 1;
      var set_vectors_value:Number = 1;
      var set_text_value:Number = 1;

       

      // Set up event listeners to handle changes in dropdown selections
      var objListener:Object = new Object();
      objListener.change = function() {
          set_objects_value = set_objects.selectedItem.data;
      }
      set_objects.addEventListener("change", objListener);

       

      var effListener:Object = new Object();
      effListener.change = function() {
          set_effects_value = set_effects.selectedItem.data;
      }
      set_effects.addEventListener("change", effListener);

       

      var vecListener:Object = new Object();
      vecListener.change = function() {
          set_vectors_value = set_vectors.selectedItem.data;
      }
      set_vectors.addEventListener("change", vecListener);

       

      var txtListener:Object = new Object();
      txtListener.change = function() {
          set_text_value = set_text.selectedItem.data;
      }
      set_text.addEventListener("change", txtListener);

       

      // Set up the button event listener's function
      function convertToPSD() {
          // Piece together the Fireworks javascript command
          var cmd:String      = 'function convertToPSD() {'
                          + '        if (fw.documents.length == 0) { return; };'
                         
                          + '        fw.setPref("PsdExport_Warn100", false);'
                          + '        fw.setPref("PsdExport_Layers", ' + set_objects_value + ');'
                          + '        fw.setPref("PsdExport_Effects", ' + set_effects_value + ');'
                          + '        fw.setPref("PsdExport_Vectors", ' + set_vectors_value + ');'
                          + '        fw.setPref("PsdExport_Text", ' + set_text_value + ');'
                     
                          + '        var dom    = fw.getDocumentDOM();'
                         
                          + '        var currentPage = dom.currentPageNum;'
                         
                          + '        for (var i = 0, len = dom.pagesCount; i < len; i++) {'
                     
                          + '            alert("Exporting page " + (i + 1) + " to PSD...");'
                     
                          + '            dom.changeCurrentPage(i);'
                          + '            dom    = fw.getDocumentDOM();'
                     
                          + '            var pathname = dom.filePathForSave;'
                          + '            pathname = pathname.slice(0, pathname.length - 4 - dom.docTitleWithoutExtension.length);'
                          + '            Files.createDirectory(pathname + "PagesToPSD_output");'
                          + '            var filename = pathname + "PagesToPSD_output" + "/" + dom.pageName + ".psd";'
                          + '            fw.exportPSD(null, filename);'
         
                          + '        }'
                 
                          + '        dom.changeCurrentPage(currentPage);'
                         
                          + '}';
                 
          // trace(cmd);
          MMExecute(cmd);
      }

       

      // When the "Export" button is pressed, call the "cmd" command and watch the magic happen (well, not yet...)
      export_btn.addEventListener("click", convertToPSD);

        • 1. Re: AAAARGH! Flash panel to Fireworks communication
          John Dunning Level 1

          Hi, Doug.


          Sorry for the slow response.  Just came across your question.  I don't see anything immediately wrong with your script, but it's likely that FW doesn't like something about the way you're building up the string of JS and passing it to MMExecute.


          This Fireworks recipe (which I happened to just post) describes a different way of handling JS code in Flash panels that avoids having to escape long strings of code: http://bit.ly/3IXuba


          The JSON Panel extension avoids Flash altogether and lets you create a panel using only JavaScript: http://bit.ly/cd6Mk  The advantage is that you write the JS that talks to the FW API just as you would in any .jsf file.  You can create the UI for the panel using a JS object that specifies a hierarchy of Flex 3 controls.  It's pretty easy to quickly create a simple UI. 


          Anyway, hope that helps.