Can't make class into type reference error

How comes I get this error?

Can’t make «class titl» of «class curR» of «class matT» “wallpaper_type” into type reference.

with


on clicked theObject
	tell matrix "wallpaper_type"
		log title of current row
	end tell
end clicked

I see lots of things with your code that are either wrong or which I would highly recommend against.

One thing contributing to your error, is that you’re asking one of the matrix’s properties for the value of a property it doesn’t have. The “current row” property is is a property of the matrix that returns an index, such as ‘row 5’. I’m pretty sure that 5 doesn’t have a title. You’ve got to remember that a matrix can have multiple columns, not just multiple rows. To get info about the matrix’s current selection, you need to check what the current cell is. The “current cell” property of the matrix actually points to a real object, which does have properties such as ‘title’ or ‘name’.

You also have an incomplete reference to the matrix in your ‘tell’ statement. The matrix cannot exist outside of the context of a window, so the reference you make to it must be something like matrix “someMatrix” of window “someWindow”.

I strongly recommend avoiding the use of evaluating objects based on their ‘title’ property. ALWAYS give EVERY object you plan to evaluate programmatically an applescript name or a tag. While you may not see it at this point in your development career, you are limiting the growth potential of your projects by allowing your code to become so dependent on your interface. This will become especially obvious when you go to localize a project some day, and you have to go through and figure out how to rewrite your code to check for everything based on titles for an endless number of other lamguages. If you use the name instead of the title, it doesn’t matter what it’s title is and you never have to make a change to your code if you decide to change the title in the future for any reason. As a general rule, you should only set the title of an object. Never get it and use it in your code to make programmatic decisions.

You have a scope problem with your log statement. There is no reason for the log statement to be inside of your tell block. You should, on one line, get the value of the property you need from your matrix. Then continue with your code in the scope of your main script. In this case, the object probably passes the log command up to the script automatically, so it will likely not cause a problem. Some scopes or objects will not respond to the log command, though, in which case you could get a difficult to find error. Or, it may simply skip the line and you’ll get frustrated trying to figure out why it isn’t logging. Such is the case with issuing a log command in a Finder tell block. Always be conscious of what you’re doing inside of a tell block. Every time you write “tell”, look between the ‘tell’ and ‘end tell’, and make sure that everything inside the block really belongs there. One way to make sure you’re only putting what you need inside is to use one-liner tell statements whenever you’re just issuing a single command, so you never run the risk of changing the scope of a statement.

Here’s my version, with examples for connecting to both the matrix itself and to another control…

on clicked theObject
	if name of theObject is "matrix" then
		--> Connected to the matrix itself
		set currentCellName to (name of (current cell of theObject)) as string
		log currentCellName

	else if name of theObject is "goButton_goButton_go" then
		--> Connected to some other control, like a button
		set currentCellName to (name of (current cell of matrix "wallpaper_type" of window "super_window")) as string
		log currentCellName

	end if
end clicked

Thanks Jobu,

What an excellent full and well explained response. Thank you very much.

I have to admit that I’m finding ASS very hard to jump in and out of quickly. I’m a web developer ordinarily and I find I spend a lot of time jumping between server administration, PHP dev, Ruby On Rails, SQL, JavaScript, ImageMagick, FFMPEG and a billion other things so ASS is normally something I have to hack at examples to get them to do what they want as I don’t really have time to learn it fully but I’ll take what you’ve said on board and see if I can clean upsome of my code.

Kevin Monk.

I think I’m getting techie burn out here.

Someone please help. I think I must have a fundamentally flawed concept of how ASS works.

Im still getting a can’t make content into type reference (-1700) error.

on drop theObject drag info dragInfo

	if name of theObject is "WallpaperTable" then
		
		-- Get the list of data types on the pasteboard
		set dataTypes to types of pasteboard of dragInfo
		
		-- We are only interested in either "file names" or "color" data types
		if "file names" is in dataTypes then
			-- Initialize the list of GIFanimationFiles to an empty list
			set theWallpaperFiles to {}
			
			-- We want the data as a list of file names, so set the preferred type to "file names"
			set preferred type of pasteboard of dragInfo to "file names"
			
			-- Get the list of GIFanimationFiles from the pasteboard
			set theWallpaperFiles to contents of pasteboard of dragInfo
			
			-- Make sure we have at least one item
			if (count of theWallpaperFiles) > 0 then
				-- Turn off the updating of the views
				set update views of WallpaperFilesDataSource to false
				
				-- For every item in the list, make a new data row and set it's contents
				repeat with theItem in theWallpaperFiles
					
					set theName to (call method "lastPathComponent" of theItem) as string
					set theName to first word of theName as string
					
					if theName is in NameWallpaperFileNames then
						log "It exists"
						if theItem contains "portrait" then
							set (contents of data cell "Portrait" of data row of theObject where data cell "Name" is theName) to quoted form of theItem
						else if theItem contains "square" then
							set (contents of data cell "Square" of data row of theObject where data cell "Name" is theName) to quoted form of theItem
						else
							set (contents of data cell "Landscape" of data row of theObject where data cell "Name" is theName) to quoted form of theItem
						end if
					else
						
						set theDataRow to make new data row at end of data rows of WallpaperFilesDataSource
						
						set contents of data cell "Name" of theDataRow to theName
						
						
						if theItem contains "portrait" then
							set contents of data cell "Portrait" of theDataRow to quoted form of theItem
						else if theItem contains "square" then
							set contents of data cell "Square" of theDataRow to quoted form of theItem
						else
							set contents of data cell "Landscape" of theDataRow to quoted form of theItem
						end if
						
						set contents of data cell "Image" of theDataRow to theItem
						
						set NameWallpaperFileNames to NameWallpaperFileNames & theName
						set WallpaperFileNames to WallpaperFileNames & {quoted form of theItem}
						-- set WallpaperFileNamesUnquoted to WallpaperFileNamesUnquoted & {theItem}
					end if
					
				end repeat
				
				-- Turn back on the updating of the views
				set update views of WallpaperFilesDataSource to true
				
				
				
			end if
		end if
	end if
	return true
end drop

this is where it’s going wrong and this is ideally what i’d liek to do.


if theName is in NameWallpaperFileNames then
      (*If there is already a relevant row then point to that row*)
      set theDataRow to data row of theObject where data cell "Name" is theName
         else
     (*else make a new row *)
      set theDataRow to make new data row at end of data rows of WallpaperFilesDataSource
end if

  (* Do all sorts of things to theDataRow reference *)