2 Replies Latest reply on Jul 28, 2009 11:52 AM by Jim_Babbage

    AAAARGH! Flash panel to Fireworks communication

    Doug Hungarter Level 1

      Sorry to be a pain and post this in both spots on the forums, but this one seems to be more active than the Extensions area.

       

      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
          Doug Hungarter Level 1

          This is uglier, but I found that making the long MMExecute function a single string instead of concatenating a bunch of smaller strings works better.

          Also, FW didn't like this line coming from Flash:

           

              if (fw.documents.length == 0) { return };

           

          Here is the finalized actionscript. Hopefully, the extension will be in the Exchange shortly : )

           

          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() {
              var cmd:String = '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);';
             
              MMExecute(cmd);
          }

           

          // When the "Export" button is pressed, call the "cmd" command and watch the magic happen
          export_btn.onRelease = convertToPSD;

          • 2. Re: AAAARGH! Flash panel to Fireworks communication
            Jim_Babbage Level 4

            Can't wait to give this a try, Doug! Great work!

             

            Jim Babbage