3 Replies Latest reply: Jun 12, 2014 3:30 AM by miso72345 RSS

    activeDocument null after LCDS-driven events

    Steven Erat Community Member

      ====================================================

      Problem:

      ====================================================

      Prob 1) In a popup TitleWindow I have a LCDS-driven Dataservice that populates an ArrayCollection "photos".  See PreviewImage.mxml source below.  On a CollectionChange event on "photos" I have a listener "dataChangeListener(event:CollectionEvent)".  That listener in turn calls a static method NewsAgencyPhotoshop.updateMetadata(args).

       

      While an image is open in PS, in NewsAgencyPhotoshop.updateMetadata(args) function I get the active Photoshop document reference, check if its not null, and proceed to udpate the activedocument metadata via the "info" property.  Example:

                  var app:Application = Photoshop.app;
                   var docRef:Document = app.activeDocument;           
                   if(docRef != null){
                       var docInfo:DocumentInfo = docRef.info;

                     .....

       

      However, every time I check if docRef is null, it is null.  I use the same lines of code to get a reference to the active document in other functions like close() or writeWatermark(), and in each of those cases the docRef object is valid (not null).

       

      It seems that when a static function is called on the NewsAgencyPhotoshop by manually clicking on a button or such that the activeDocument reference is good, but when I call a static function as an event listener for a LCDS related event, then the activeDocument is always null. 

       

      Why?

       

      Prob 2) I also tried making the activeDocument reference a static class variable, and then in the static functions just access the references.  In the open(filePath) function I instantiate the static class variables, like this:

       

              public static function open(filePath:String):void
               {
                   app = Photoshop.app;
                   var file:File;
                   file = new File(filePath);
                   app.open(file);
                   docRef = app.activeDocument;
               }

       

      Using this approach, functions driven by manual events work and have good docRefs, such as this:

       

              public static function writeWaterMark():void
              {
                  //var app:Application = Photoshop.app;
                  //var docRef:Document = app.activeDocument;
                  var myTextLayerRef:ArtLayer = docRef.artLayers.add();

       

      However, this only partly works with the function called by my LCDS change event listener, since the docRef is then not null it enters the code block and attempts to write the metadata to the activedocument, like this:

       

              public static function updateMetadata(filePath:String, data:Object):void
               {
                   //var app:Application = Photoshop.app;
                   //var docRef:Document = app.activeDocument;           
                   if(docRef != null){
                       var docInfo:DocumentInfo = docRef.info;
                       docInfo.copyrightNotice = data.copyrightNotice;

       

       

      The problem here is that the  docInfo.copyrightNotice line throws the following exception in Flash Builder:

       

      2/17/2011 00:08:44.226 [INFO]  com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event  of type com.adobe.csxs.internally.events.BroadcastEvent to all  extensions.
      Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
      - <no additional information available>
           at flash.external::HostObject/__set()
           at com.adobe.csawlib::CSHostObject/hostSet()
           at com.adobe.photoshop::DocumentInfo/set copyrightNotice()
           at NewsAgencyPhotoshop$/updateMetadata()[/opt/Adobe_Flash_Builder4/NewsAgency_Ext/src/NewsAg encyPhotoshop.as:52]
           at PreviewImage/dataChangeListener()[/opt/Adobe_Flash_Builder4/NewsAgency_Ext/src/PreviewIma ge.mxml:103]

       

      Your advice is appreciated.

       

      Thank you,

      Steven Erat

       

       

      ====================================================

      Environment

      ====================================================

      Photoshop CS5 Extended 12.01 x32

      Flash Builder 4

      CS SDK 1.02

      Extension Builder SDK 3.4

      MacBook Pro / OS X 10.5 / Intel Core 2 Duo 2.66 GHz / Procs: 1 / Cores: 2 / Memory: 8 GB

      App configured for Photoshop CS5 and Photoshop CS5 Extended

       

       

      ====================================================
      PreviewImage.mxml (the popup)

      ====================================================

      <?xml version="1.0" encoding="utf-8"?>    
      <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="com.stevenerat.news.*"
          title="Preview Image" horizontalAlign="center"  verticalAlign="middle" horizontalScrollPolicy="off" verticalScrollPolicy="off"
          paddingBottom="20" paddingLeft="20" paddingRight="20" paddingTop="20" width="270" height="550"
           creationComplete="init();">

      ....
         
          <mx:Script>
              <![CDATA[      
                  import flash.events.TimerEvent;
                  import flash.utils.Timer;
                 
                  import mx.events.CollectionEvent;
                  import mx.managers.PopUpManager;
                  import mx.utils.ObjectUtil;

      ....

                     
                  public function init():void{
                      ds.fill(photos);
                      ....
                  }

      ....
                  private function dataChangeListener(event:CollectionEvent): void
                  {
                      if(lblStatus != null && imgIsOpen){ 
                          lblStatus.text = "UPDATED METADATA";
                          setButtonState(false,true,true);
                          var data:Array = event.currentTarget.list.localItems;
                          for(var i:int=0;i<data.length;i++){
                              if (data[i].fileName == this.fileName){
                                  NewsAgencyPhotoshop.updateMetadata(data[i].dirPath+data[i].fileName,data[i]);
                                  break;
                              }
                          }
                      }
                  }

      ....

          <mx:DataService id="ds" destination="NewsAgencyPhotos" autoSyncEnabled="true" autoCommit="false"/>
           <mx:ArrayCollection id="photos" collectionChange="dataChangeListener(event)"/>
           <NewsPhoto/>

       

       

       

       

       

       

      ====================================================

      NewsAgencyPhotoshop.as

      ====================================================

      package
      {
          import com.adobe.csawlib.photoshop.Photoshop;
          import com.adobe.photoshop.*;
        
          import flash.filesystem.File;
          import mx.utils.ObjectUtil;
         
          public class NewsAgencyPhotoshop
          {
              public static var app:Application;
              public static var docRef:Document;
             
              public static function open(filePath:String):void
              {
                  app = Photoshop.app;
                  var file:File;
                  file = new File(filePath);
                  app.open(file);
                  docRef = app.activeDocument;
              }       
      ....

             
              public static function updateMetadata(filePath:String, data:Object):void
              {
                  //var app:Application = Photoshop.app;
                  //var docRef:Document = app.activeDocument;           
                  if(docRef != null){
                      var docInfo:DocumentInfo = docRef.info;
                      docInfo.copyrightNotice = data.copyrightNotice;
                      docInfo.headline = data.headline;
                      var keywordSt:String = data.keywords;
                      var keywordAry:Array = keywordSt.split(",");
                      for (var i:int=0;i<keywordAry.length;i++){
                          docInfo.keywords[i] = keywordAry[i];
                      }
                      docInfo.caption = data.description;
                      docInfo.city = data.city;
                      docInfo.country = data.country;
                      docInfo.provinceState = data.state;
              }

       

       

       

       

      ====================================================

      Console

      ====================================================

      [SWF] StageManager-2.0.swf - 1,188,270 bytes after decompression
      2/17/2011 00:08:18.971 [INFO] com.adobe.csxs.stagemanager.StageManager creationComplete()
      2/17/2011 00:08:18.981 [INFO] com.adobe.csxs.stagemanager.external.ExternalEventReceiver ExternalInterface callback registered.
      2/17/2011 00:08:18.982 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver ExternalInterface callback registered.
      2/17/2011 00:08:18.984 [INFO] com.adobe.csxs.command.GetPendingStageManagerIdCommand calling GetPendingStageManagerId through ExternalInterface
      2/17/2011 00:08:18.993 [INFO] com.adobe.csxs.command.GetPendingStageManagerIdCommand execute() PlugPlug returned StageManager ID.
      2/17/2011 00:08:19.026 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension CH
      2/17/2011 00:08:19.027 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension com.example.helloworld.extension1
      2/17/2011 00:08:19.028 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension BASICAMFCONNECTOR
      2/17/2011 00:08:19.028 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension CSREVIEW
      2/17/2011 00:08:19.028 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension HELLOPHO
      2/17/2011 00:08:19.029 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension KLR
      2/17/2011 00:08:19.029 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension com.stevenerat.news.extension1
      2/17/2011 00:08:19.029 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension CREATENEWCSREVIEW
      2/17/2011 00:08:19.030 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension NETAVERAGES
      2/17/2011 00:08:19.030 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension com.adobe.rc.mymessages
      2/17/2011 00:08:19.030 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension CHWE
      2/17/2011 00:08:19.031 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension com.adobe.rc.operationalmessages
      2/17/2011 00:08:19.031 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension STORY
      2/17/2011 00:08:19.032 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension FRIO
      2/17/2011 00:08:19.032 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension MINIBR
      2/17/2011 00:08:19.032 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension BLCSLIVE
      2/17/2011 00:08:19.033 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension CHSIGNIN
      2/17/2011 00:08:19.033 [INFO] com.adobe.csxs.stagemanager.model.ExtensionManager Adding extension swfpanel-onOne-0
      2/17/2011 00:08:19.034 [INFO] com.adobe.csxs.stagemanager.extension.impl.ExtensionLoader ExtensionLoader() registering ExternalInterface callback loadExtension
      2/17/2011 00:08:19.034 [INFO] com.adobe.csxs.stagemanager.extension.impl.ExtensionLoader ExtensionLoader() registering ExternalInterface callback unloadExtension
      2/17/2011 00:08:19.035 [INFO] com.adobe.csxs.stagemanager.extension.impl.ExtensionLoader checkLoadingQueue()
      2/17/2011 00:08:19.037 [INFO] com.adobe.csxs.command.GetLoadingQueueCommand calling GetLoadingQueue through ExternalInterface
      2/17/2011 00:08:19.041 [INFO] com.adobe.csxs.command.GetLoadingQueueCommand execute() PlugPlug returned extensions to be loaded.
      2/17/2011 00:08:19.042 [INFO] com.adobe.csxs.stagemanager.extension.impl.ExtensionLoader loadExtension() com.stevenerat.news.extension1
      2/17/2011 00:08:19.045 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Extension com.stevenerat.news.extension1 is not a plugin extension -> validating.
      2/17/2011 00:08:19.049 [INFO] com.adobe.csxs.stagemanager.security.impl.ExtensionValidator In debug mode the extension signature is not validated.
      2/17/2011 00:08:19.053 [INFO] com.adobe.csxs.command.SetExtensionSignedCommand calling SetIsSigned through ExternalInterface
      2/17/2011 00:08:19.133 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager doLoadExtension() Extension com.stevenerat.news.extension1 loaded.
      2/17/2011 00:08:19.230 [INFO] com.adobe.csxs.stagemanager.window.ExtensionWindow onCreationComplete()
      [SWF] Users/stevenerat/Library/Application Support/Adobe/CS5ServiceManager/extensions/com.stevenerat.news/NewsAgencyPhotos.swf - 1,976,113 bytes after decompression
      2/17/2011 00:08:19.369 [INFO] com.adobe.csxs.stagemanager.window.ExtensionWindow Loading of extension com.stevenerat.news.extension1 complete.
      2/17/2011 00:08:19.371 [INFO] com.adobe.csxs.stagemanager.window.impl.SWFEventDispatcher Loading of extension com.stevenerat.news.extension1 complete.
      2/17/2011 00:08:19.396 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all extensions...
      2/17/2011 00:08:19.397 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      2/17/2011 00:08:20.230 [INFO] com.adobe.csxs.stagemanager.extension.impl.ExtensionLifeCycleNotifier onExtensionComplete()
      2/17/2011 00:08:20.231 [INFO] com.adobe.csxs.command.SetExtensionLoadedCommand calling SetIsLoaded through ExternalInterface
      2/17/2011 00:08:20.233 [INFO] com.adobe.csxs.stagemanager.extension.impl.ExtensionLifeCycleNotifier dispatchInvokeEvent()
      2/17/2011 00:08:20.236 [INFO] com.adobe.csxs.command.CheckStartOnEventCommand calling CheckStartOnEvent through ExternalInterface for com.stevenerat.news.extension1
      2/17/2011 00:08:20.245 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowStateManager onExtensionComplete()
      2/17/2011 00:08:20.252 [INFO] com.adobe.csxs.stagemanager.window.impl.SWFEventDispatcher dispatchEventToExtension() Dispatching event of type com.adobe.csxs.events::StateChangeEvent to extension com.stevenerat.news.extension1
      2/17/2011 00:08:20.257 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all extensions...
      2/17/2011 00:08:20.258 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      2/17/2011 00:08:31.858 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all extensions...
      2/17/2011 00:08:31.859 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      2/17/2011 00:08:33.333 [INFO] com.adobe.csxs.stagemanager.window.impl.SWFEventDispatcher dispatchEventToExtension() Dispatching event of type com.adobe.csxs.events::StateChangeEvent to extension com.stevenerat.news.extension1
      2/17/2011 00:08:36.394 [INFO] com.adobe.csxs.stagemanager.window.impl.SWFEventDispatcher dispatchEventToExtension() Dispatching event of type com.adobe.csxs.events::StateChangeEvent to extension com.stevenerat.news.extension1
      2/17/2011 00:08:36.683 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all extensions...
      2/17/2011 00:08:36.683 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      2/17/2011 00:08:36.718 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all

      .......
      2/17/2011 00:08:44.132 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      2/17/2011 00:08:44.190 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all extensions...
      2/17/2011 00:08:44.191 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      2/17/2011 00:08:44.209 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all extensions...
      2/17/2011 00:08:44.209 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      2/17/2011 00:08:44.225 [INFO] com.adobe.csxs.stagemanager.external.CSXSEventReceiver receiveExternalEvent() dispatching CSXSEvent to all extensions...
      2/17/2011 00:08:44.226 [INFO] com.adobe.csxs.stagemanager.window.impl.WindowManager Dispatching event of type com.adobe.csxs.internally.events.BroadcastEvent to all extensions.
      Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
      - <no additional information available>
          at flash.external::HostObject/__set()
          at com.adobe.csawlib::CSHostObject/hostSet()
          at com.adobe.photoshop::DocumentInfo/set copyrightNotice()
          at NewsAgencyPhotoshop$/updateMetadata()[/opt/Adobe_Flash_Builder4/NewsAgency_Ext/src/NewsAg encyPhotoshop.as:52]
          at PreviewImage/dataChangeListener()[/opt/Adobe_Flash_Builder4/NewsAgency_Ext/src/PreviewIma ge.mxml:103]
          at PreviewImage/__photos_collectionChange()[/opt/Adobe_Flash_Builder4/NewsAgency_Ext/src/Pre viewImage.mxml:163]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.collections::ListCollectionView/dispatchEvent()[C:\autobuild\3.4.0\frameworks\projects \framework\src\mx\collections\ListCollectionView.as:862]
          at mx.collections::ListCollectionView/handlePropertyChangeEvents()[C:\autobuild\3.4.0\framew orks\projects\framework\src\mx\collections\ListCollectionView.as:1224]
          at mx.collections::ListCollectionView/listChangeHandler()[C:\autobuild\3.4.0\frameworks\proj ects\framework\src\mx\collections\ListCollectionView.as:1096]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.data::ConcreteDataService/dispatchCollectionEvent()[C:\depot\flex\branches\enterprise_ bridgeman_final_hotfixes\frameworks\mx\data\ConcreteDataService.as:4404]
          at mx.data::ConcreteDataService/itemUpdateHandler()[C:\depot\flex\branches\enterprise_bridge man_final_hotfixes\frameworks\mx\data\ConcreteDataService.as:4946]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at com.stevenerat.news::NewsPhoto/dispatchEvent()[/opt/Adobe_Flash_Builder4/NewsAgency_Ext/s rc/com/stevenerat/news/NewsPhoto.as:26]
          at mx.data.utils::Managed$/setProperty()[C:\depot\flex\branches\enterprise_bridgeman_final_h otfixes\frameworks\mx\data\utils\Managed.as:383]
          at com.stevenerat.news::NewsPhoto/set description()[/opt/Adobe_Flash_Builder4/NewsAgency_Ext/src/com/stevenerat/news/NewsPhoto. as:13]
          at mx.data::ConcreteDataService/updateManagedProperty()[C:\depot\flex\branches\enterprise_br idgeman_final_hotfixes\frameworks\mx\data\ConcreteDataService.as:5618]
          at mx.data::ConcreteDataService/updateMergedItem()[C:\depot\flex\branches\enterprise_bridgem an_final_hotfixes\frameworks\mx\data\ConcreteDataService.as:5638]
          at mx.data::ConcreteDataService/mergeUpdate()[C:\depot\flex\branches\enterprise_bridgeman_fi nal_hotfixes\frameworks\mx\data\ConcreteDataService.as:5155]
          at mx.data::ConcreteDataService/http://www.adobe.com/2006/flex/mx/internal::mergeMessage()[C:\depot\flex\branches\enterpri se_bridgeman_final_hotfixes\frameworks\mx\data\ConcreteDataService.as:2555]
          at mx.data::ConcreteDataService/messageHandler()[C:\depot\flex\branches\enterprise_bridgeman _final_hotfixes\frameworks\mx\data\ConcreteDataService.as:5199]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.messaging::AbstractConsumer/http://www.adobe.com/2006/flex/mx/internal::messageHandler()[C:\autobuild\3.4.0\frameworks \projects\rpc\src\mx\messaging\AbstractConsumer.as:765]
          at mx.messaging::ConsumerMessageDispatcher/messageHandler()[C:\autobuild\3.4.0\frameworks\pr ojects\rpc\src\mx\messaging\ConsumerMessageDispatcher.as:261]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.messaging::ChannelSet/messageHandler()[C:\autobuild\3.4.0\frameworks\projects\rpc\src\ mx\messaging\ChannelSet.as:1457]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.messaging.channels::NetConnectionChannel/receive()[C:\autobuild\3.4.0\frameworks\proje cts\rpc\src\mx\messaging\channels\NetConnectionChannel.as:318]

        • 1. Re: activeDocument null after LCDS-driven events
          Mark Erickson

          Steven,

           

          You have run into a Photoshop Mac bug involving events, a description, workaround and library are described here:

           

          http://cookbooks.adobe.com/post_Creative_Suite_5_Extensions_and_Photoshop_CS5_Redu-17727.h tml

           

          You can download the library.swf as well as a sample project from this page. As you have seen, the problem is that after receiving an event, the active document as well as other Photoshop DOM references will be null. The workaround kicks Photoshop into making the DOM valid, essentially re-executing your function with a valid context.

           

          Since the cookbook post was written by Bob, I've been using the workaround frequently with success, of course we are also working closely with the Photoshop team to get it fixed. Again, as you have seen this is a problem for LCDS, but it is also needed in frameworks like PureMVC as well as FlexUnit.

           

          Here is my one line version of the code I place at the top of each function called by these events.

           

          if (Utilities.shouldForceClean()) if (PsEventScrubber.getInstance().forceClean( this, arguments.callee, arguments ) != null ) return; // Workaround

           

          Note you mentioned creating a static function, with a static you can't use "this", just replace this with your class:

           

          if (Utilities.shouldForceClean()) if (PsEventScrubber.getInstance().forceClean( MyClassHere, arguments.callee, arguments ) != null ) return; // Workaround

           

          Finally, the Utilities.shouldForceClean() is my simple check that prevents even making the call. Although Bob wrote PsEventScrubber to do a platform check, I put this in to avoid even calling when not on a mac. This is also a stub for a function that could detect the bug and avoid making the call in a future version when it is fixed.

           

          /**

          * Utility to specifically target Photoshop Mac Bug - Ps Bug# 2584580

          */

          public static function shouldForceClean(): Boolean {

          return ( flash.system.Capabilities.os.indexOf("Mac OS") == 0 );

          }

           

          Let us know how this works for you.

           

          - Mark

          • 2. Re: activeDocument null after LCDS-driven events
            Steven Erat Community Member

            Mark, thanks so much for your help!

             

            I've had that article printed and sitting on my desk, but had not yet read it.  The solution worked, and I'm thrilled that I've now been able to complete the demo application that I'll be using for an upcoming talk in Edinburgh about using the CS SDK and Extension Builder with LCDS and a ColdFusion backend.

             

            For the benefit of anyone else reading this, I'll show how I used the solution in simple terms.  In my PreviewImage.mxml popup window that has a dataservice to update a photos:ArrayCollection object, I took the following steps:

             

            1) Download PsMacDom.zip and *manually* unzip it via the command line (double clicking the zip incorrectly extracts the swc into a swf + xml, so don't do that).

            2) Add the PsMacDom.swc file to my project Build Path.

            3) import com.adobe.devtech.PsEventScrubber;

            4) Write a proxy handler for the event that scrubs the event if on a Mac OS (and associated utility to check the OS)

            5) Pass the scrubbed event to the original event listener function.

            6) Designate the collectionChange listener to be the proxy function

             

             

                       
                        // Workaround for issue that affects Mac computers and Photoshop DOM calls in the context of a system/network/timer event
                        // http://cookbooks.adobe.com/post_Creative_Suite_5_Extensions_and_Photoshop_CS5_Redu-17727.h tml
                        public function dataChangeProxyHandler( event: CollectionEvent ): void
                        {
                            if(shouldForceClean()) {PsEventScrubber.getInstance().scrubEvent( event, dataChangeListener)};
                        }
                       
                        public static function shouldForceClean(): Boolean {
                            return ( flash.system.Capabilities.os.indexOf("Mac OS") == 0 );
                        }
                       
                        private function dataChangeListener(event:CollectionEvent): void
                        {
                            if(lblStatus != null && imgIsOpen){ 
                                lblStatus.text = "UPDATED METADATA";
                                setButtonState(false,true,true);
                                var data:Array = event.currentTarget.list.localItems;
                                for(var i:int=0;i<data.length;i++){
                                    if (data[i].fileName == this.fileName){
                                        NewsAgencyPhotoshop.updateMetadata(data[i].dirPath+data[i].fileName,data[i]);
                                        break;
                                    }
                                }
                            }
                        }

             

            ....

                <mx:DataService id="ds" destination="NewsAgencyPhotos" autoSyncEnabled="true" autoCommit="false"/>
                <mx:ArrayCollection id="photos" collectionChange="dataChangeProxyHandler(event)"/>
                <NewsPhoto/>

            • 3. Re: activeDocument null after LCDS-driven events
              miso72345

              Thanks for the link, Mark. It is not valid anymore, but can be accessed through the Internet Time Machine:

               

              http://web.archive.org/web/20101007213022/http://cookbooks.adobe.com/post_Creative_Suite_5 _Extensions_and_Photoshop_CS5_Redu-17727.html

               

              ...you have only few seconds before it redirects you back to current adobe server, so just quickly save the page to your disk and open it from there. Here are the download links to those 2 zip files needed for the workaround:

               

              PsMacDomswc.zip [PS mac-safe workaround swc file]:

              http://web.archive.org/web/20101007213022/http://cookbooks.adobe.com/index.cfm?event=getFi le&fileId=7265

               

              PsDomEvents.zip [Sample Project]:

              http://web.archive.org/web/20101007213022/http://cookbooks.adobe.com/index.cfm?event=getFi le&fileId=7266