Use of type enum of constants in Applescript

Help ! Please.

First the code (extract of) :

log return & "¢¢¢ TEST :" & return
        -- Note for NSColor constants it's OK  ...
        set cc to whiteColor() of current application's class "NSColor" -- or set cc to NSColor's whiteColor()
        log cc
        --cc's colorUsingColorSpaceName_(NSCalibratedRGBColorSpace)
        log current application's NSCalibratedRGBColorSpace
        log "--a"
        -- Now the trouble
        log current application's NSBitmapImageFileType
        set typeImageBitmap to current application's NSBitmapImageFileType as list
        log "--b"
        log count of typeImageBitmap 
        log "--c"
        set t to NSPNGFileType of typeImageBitmap
        log t
        set tt to current application's class "NSBitmapImageRep"
        log tt
        --set ttt to  NSBitmapImageFileType() of tt -- current application's class "NSBitmapImageRep"'s
        --log ttt
        set tttt to NSBitmapImageFileType of current application's class "NSBitmapImageRep"
        log "--d"
        --set tttt to current application's class "NSBitmapImageRep"'s NSBitmapImageFileType's NSPNGFileType
        log class of tttt
        --set typePNG to NSPNGFileType of NSBitmapImageRep
        --tell NSBitmapImageRep to set typePNG to NSPNGFileType of NSBitmapImageFileType
        -- == AU SECOURS ! ! ! =====================================================================================
        unlockFocus() of champ
        set donnees to alloc() of NSData
        tell representationImage 
            -- next line is just a workaround !  I want to write one of the preceding --
            set typeImageBitmap to 1 -- TIFF , 5 for PNG ... etc
            set donnees to representationUsingType_properties_(typeImageBitmap, null)
        end tell
        tell donnees to writeToFile_atomically_("/tmp/test.tiff",false)

How i can wite the line

set typeImageBitmap to 1

for acces to the value defined in class NSBitmapImageRep, instead of hard coded “1”

thank you



set typeImageBitmap to current application's NSPNGFileType
log typeImageBitmap --> 4

Hi Stephan,

Thank you, it works !!
I changed my code accordingly.

lockFocus() of champ
           set  representationImage to alloc() of NSBitmapImageRep
           tell representationImage to initWithFocusedViewRect_(cadre)
        unlockFocus() of champ
        -- 0 NSTIFFFileType, 1 NSBMPFileType, 2 NSGIFFileType, 3 NSJPEGFileType, 4 NSPNGFileType, 5 NSJPEG2000FileType.
        set donnees to alloc() of NSData
        set donnees to representationUsingType_properties_(current application's NSPNGFileType, null) of representationImage

Against by now I have this error message for ‘NS…FileType’ different of BMP (1)

Strange …?

every alloc() should be followed by an init(), in case of NSData initWithData_()

set donnees to NSData's alloc()'s initWithData_(representationImage's representationUsingType_properties_(current application's NSPNGFileType, missing value))

for me the 's syntax is better readable

Stephnan, As you must imagine, I’m completely beginner with ASOC, which explains my mistakes.
Do you know what is the difference in code generated from an alloc-init in one line and two lines? The memory area is not reserved, it is lost?
Again thank you for your help and your advice.

There is no difference. But mostly alloc/init in one line is used