Easy JSX to AS translation... wrong!?

General Discussion of Scripting for Flex, Flash & CS SDK

Moderators: Tom, Kukurykus

undavide

Easy JSX to AS translation... wrong!?

Post by undavide »

Hello,
I'm doing my first attempt to write some AS code - and I feel totally dumb since it seems I can't translate this JSX test code...

Code: Select allvar docRef = app.activeDocument;
var myLayer = docRef.activeLayer;
var dupLayer = myLayer.duplicate();
dupLayer.applyGaussianBlur (20);
dupLayer.desaturate();
dupLayer.blendMode = BlendMode.OVERLAY;

...into AS. It should be really really easy, but this one:

Code: Select allvar docRef:Document = app.activeDocument;
var myLayer:ArtLayer = docRef.activeLayer;
var dupLayer:ArtLayer = myLayer.duplicate();
dupLayer.applyGaussianBlur(20);
dupLayer.desaturate()
dupLayer.blendMode = BlendMode.OVERLAY;

gives me two errors: "Implicit coercion of a value with static type com.adobe.photoshop:Layer to a possibly unrelated type com.adobe.photoshop:ArtLayer"
(which I translate: "stupid, myLayer and dupLayer are Layer and not ArtLayer"")

while this code:

Code: Select allvar docRef:Document = app.activeDocument;
var myLayer:Layer = docRef.activeLayer;
var dupLayer:Layer = myLayer.duplicate();
dupLayer.applyGaussianBlur(20);
dupLayer.desaturate()
dupLayer.blendMode = BlendMode.OVERLAY;

gives me the errors:
"Call to a possibly undefined method applyGaussianBlur through a reference with static type com.adobe.photoshop:Layer"
"Call to a possibly undefined method desaturate through a reference with static type com.adobe.photoshop:Layer"
(which I translate: "stupid, you can desaturate and applyGaussianBlur only to ArtLayer and not Layer!")

I'm missing something: in AS a photoshop layer is a Layer, to which I can't apply a filter. Filters can be applied to ArtLayers, but I can't cast ArtLayer a photoshop layer. So what am I supposed to do...

Thanks in advance,

Davide (who already miss extendscript)

PS
CS Extension Builder on Mac doesn't update code errors while saving - it needs a project run/debug. Bah.
undavide

Easy JSX to AS translation... wrong!?

Post by undavide »

Elementary, my dear Watson...

Code: Select allvar myLayer:ArtLayer = docRef.activeLayer as ArtLayer
var dupLayer:ArtLayer = myLayer.duplicate() as ArtLayer;

Lesson learned: AS is picky indeed.
And Extension Builder keeps not updating code errors when saving...

Cheers,

Davide