Image Events: File type as variable

I’ve tried several different forms of this, but basically I would like to be able to pass a variable of the file type I want Image Events to save an image as, but I get an NSInternalScriptError. If I hard code the file type in like . save this_image as JPEG2 in . it works fine.

set file_type to ("JPEG2" as Unicode text)
set the new_image to save this_image as file_type in ¬
	file new_name of the target_folder

Same thing with using a variable for scaling to an image size.

You dont need to put the JPEG2 in quotes.

tell application "Image Events"
	-- other code goes here.
	-- the following line will only work in a tell application "Image Events" block. 
	set file_type to JPEG2
	set new_image to save this_image as file_type in file new_name of target_folder
end tell