State of Checkbox within new window

I can’t seem to get the state of a checkbox within my window! It is a window that I set up in IB, so when a button in my main window is clicked it shows up, the window is named “newPostWindow”, and the checkbox is “Forum”.
I’ve already tried : if (integer value of button “Forum” of “newPostWindow”) = 1
and the version for finding the string value, but neither seem to work. What is my problem here? Anyway, any help would be appreciated, I’m tearing my hair out on this one :slight_smile:

I think that should be:

 if state of button "Forum" of window "newPostWindow" is 1

…At least I hope so, it’s been a while since I used one of those.

Thanks for the try, but no luck :frowning:
I tried: if state of button “Forum” of window “newPostWindow” is 1
and: if state of button “Forum” of “newPostWindow” is 1
and both times it gave me an error.
Anyone else?

Well? What’s the error? The error it gives you will a) tell us what the problem might be, and b) you may learn what the problem is for yourself by paying attention to the details of the error message. If it’s a 4(1) error, you’ve got a typo or an unnamed object somewhere. If it’s another error, it may be that the problem is somehow completely unrelated. ALWAYS post the errors you’re getting… they are actually valuable! :o

Both of the following work for me.

if state of button "Forum" of window "Window" is 0 then
	log "Not Checked"
else if state of button "Forum" of window "Window" = 1 then
	log "Checked"
end if

-- OR --

set forumState to state of button "Forum" of window "Window"
if forumState = 0 then
	log "Not Checked"
else if forumState = 1 then
	log "Checked"
end if

One of your examples looked fine, so I’m guessing that you’ve misspelled something or forgot to properly name an object.
j

The error I got when I removed window from
if state of button “Forum” of window “Window” is 0 then
was the "can’t make … into type integer, and the other was 4 (1) when I had window in the script.

It SHOULD work, I named everything perfectly, and I have no typos on any names, this is really frustrating!

Maybe your checkbox is a subview of sth (box/tab view) or maybe it is a cell of a matrix?
I suggest to do this test to make sure your addressing is correct:

simply connect the checkbox to an on clicked handler and log the object:

on clicked theObject
   log theObject
end on

then build and go and you can easily check the button by clicking it (see the result in Xcode’s Run Log window):

  • button id 2 of window id 1 – if it’s simply a button on a window
  • button id 3 of box id 2 of window id 1 – if it’s subview of a box
  • button id 4 of view id 3 of tab view id 2 of window id 1 – if it’s subview of a tab view
  • item id 2 - if it’s a button cell in a matrix

hope that helps …

D.

Thanks, I had never thought about logging it! Can I refer to the button be id instead of name?

EDIT: THANK YOU!!! It works wonderfully now, I’m referencing using button id, and it all works! THANK YOU!!!

This may sound funny (I’m a noob) but what now??? I’m done my project, how can I build an app, or export it or whatever?

As you’ve found, yes, you can. BUT, this is not the prefered way of doing it. In fact, In three years of creating lots of applications using ASStudio, I have never once referenced any object by ID… EVER. You should go back and try to figure out why your original code didn’t work. Something so simple as referencing an object by it’s name is a task you need to master early on. If you reference everything by ID, you have to somehow test the object (like logging the button when pressed) just to figure out what it is, before you’re ever able to write code that does anything meaningful. This is just stupid, to put it plainly. If referencing the button is not working by name then make sure it’s named correctly and that the window it’s in is referenced correctly. One common mistake is to try to type the object’s name in the ‘identifier’ field or ‘title’ field. Make sure that you’re actually putting it in the “Name:” field in the Applescript pane in the IB inspector window (cmd-8).

Another possibility here, is that your nib may be corrupted. This does happen… and is especially common with newer users. The process of learning how things work by constant, random trial-and-error… i.e. dragging things all over the place, renaming, deleting, undeleting, messing with settings, blah blah blah… seems to simply overload IB once in a while, and when you go to save the nib, it gets corrupted. Try adding a new button to the window and getting the right code to work for it. If this doesn’t work, create a new test project and try it there. If none of these tests works, it’s most likely something that you’re not understanding correctly, because people usually don’t continue to have these problems once they figure out where it is that they’re doing wrong. Don’t get in the habit of using workarounds to get things done. Especially not so early in the game, and not on something so fundamental as naming objects.

:confused: How have you been testing your app? It’s already being built somewhere. The only thing you shold do now, is to make sure of what build style it’s using. In the toolbar, there may be a popup button labelled “active build configuration”. If not, open the build results window by selectiong “Window > Tools > Build Results” from the main menu bar. That should have a build config menu. Just select “Release” and build your project again (cmd-B, cmd-R, or “Build > Build”). This will create your application in a new directory named release, in the build folder of your project. That’s your app. A release version has all the necessary linking and configuration it needs to be a full-fledged, stand-alone app. Debug versions only work within the context of being run in Xcode during develoment.

j

I should have clarified, I am refering to the button using name, not id. It just showed me what the window id was, because for some reason the name wasn’t working. Anyway, it all works now, thanks you all very much for your help!

I went to the Build Results window, and there seems to be no release button or anything. What am I missing?

OK, we’ll try another way. :rolleyes:

In Xcode, select “Project > Set Active Build Configuration > Release” from the main menu. If you’re using a (much) older version of Xcode you may have to actually look around a bit to find it, and on older machines ‘Debug’ was called ‘Development’. Honestly, there are popup buttons and menus all over the place in Xcode on all four of my machines, running both the latest, and older, versions of Xcode that enable you to switch the build config. Just look for “debug” (or development) SOMEWHERE and then switch it to “release”.

Also, you can control-click on the toolbar in xcode, and select “customize toolbar” from the menu that pops up. This will bring up the toolbar palette, where you can drag the “Active Build Configuration” menu to the toolbar so it IS there in your main window all of the time.

Sorry to be a bother, but it still doesn’t work!

I tried all those things, and it still didn’t work, I set the Active Build Style to deployment, and clicked build, but there was no new directory in my build file called release. If it means anything, Xcode says it is version 2, does ANYONE know how to do it in version 2?

viciousfishes3000,

Have you tried something as simple as doing a ‘command-f’ from the Finder and searched for your app? I’m in Xcode 2.3 and recently went through the same stuff you’re going through and the only thing in my build folder was an alias to the app. There is a hidden folder that contained the actual app when it was built (in my case). Fortunately I just had to show the original from the alias, but maybe a search will find it for you. Its an idea.:confused:

PreTech

I can find the app, that I was using for texting, but if I move the folder it came from, of move it to another computer, it dies!

Visciousfishes, I had that version of Xcode until a few weeks ago, and the Deployment build setting builds the app in the exact same place but with different linking. You also have to clean the project (click and hold on the Run icon for a menu). After that I’m pretty sure you can move everything around, delete other files, and so forth. I say I’m pretty sure because the first other computer I sent an app to was an Intel, and my Xcode wouldn’t build for it.

If all else fails, you can always do like I did and download the latest version off http://developer.apple.com/tools/xcode/. I KNOW that one builds in a different folder.

***EDIT:Whoops, this was answered in a different topic. Beaten to the punch!