Task based panels

General Discussion of Scripting for Flex, Flash & CS SDK

Moderators: Tom, Kukurykus

Mike Hale

Task based panels

Post by Mike Hale »

It has been a while since I worked with Flex so this may need syntax correction but it would look something like this...
Code: Select allprivate function myPhotoshopCallback(eventID:Number, descID:Number):void {
   var action_desc:ActionDescriptor = new ActionDescriptor();
   action_desc.fromID(descID);
   if( action_desc.hasKey((Number(s('using')))){
      var object_type:Number = action_desc.getObjectType(Number(s('using')));
      var next_action_desc:ActionDescriptor = new ActionDescriptor();
      next_action_desc = action_desc.getObjectValue((Number(s('using'))));
      if( next_action_desc.hasKey(Number(s('type'))){
        var adjustment_type:Number = next_action_desc.getObjectType(Number(s('type')));
         trace("object_type: " + object_type);
         trace("adjustment_type: " + adjustment_type);
    }
  }         
}
jacobolus

Task based panels

Post by jacobolus »

About your error from a couple posts up, the issue may be that you’re trying to access parts of the descriptor that aren’t there. (As Mike pointed out.)

For instance, to create a new empty curves adjustment layer, the descriptor looks like this:
Code: Select all$desc
    target: $ref.class 'adjustmentLayer'
    using: $desc 'adjustmentLayer',
        type: $desc 'curves',
            presetKind: $enum 'presetKindType.presetKindDefault'
My code from before pulled out the descriptor under the "using" key, and then looked inside first for what the objecttype of the descriptor was (here, 'adjustmentLayer'), and then at the "type" key inside, at the objecttype of that descriptor (here 'curves').

If you try to call Code: Select allaction_desc.getObjectValue($s('using')).getObjectType($s('type')) when the object hierarchy looks different, those keys might not exist, and it will complain at you. It would be possible to put some conditional checks in there, to make sure the keys exist before you try to fetch their contents, etc.
undavide

Task based panels

Post by undavide »

Mike, Jacob,
thanks so much for your help! I'll try as soon as possible and I'll let you know.

Davide

=====
Update

Mike's suggestion works like a charm, I paste it below again as a reference for future generations because the original has a small typo (two parenthesis missing):

Code: Select allprivate function myPhotoshopCallback(eventID:Number, descID:Number):void {
   var action_desc:ActionDescriptor = new ActionDescriptor();
   action_desc.fromID(descID);
   if(action_desc.hasKey((Number(s('using'))))) {
      var object_type:Number = action_desc.getObjectType(Number(s('using')));
      var action2:ActionDescriptor = new ActionDescriptor();
      action2 = action_desc.getObjectValue((Number(s('using'))));
      if (action2.hasKey((Number(s('type'))))) {
         var adjustment_type:Number = action2.getObjectType(Number(s('type')));
         trace("object_type: " + object_type);
         trace("adjustment_type: " + adjustment_type);            
      }
   }
}

Thanks again to both Mike and Jacob!! You've been of invaluable help, as usual. It seems some light has been shed in my mind on ActionManager code - waiting to see if some brave forum member would attempt to kick my a... ehm, to correct my rants on the same topic in this thread.
All the best, ciao!

Davide