Hey there Googie85, a few things to note -
If you go to the Dictionary, you'll find there is no 'center' property, so that is problem 1 as Jean-Marc indicated.
In your original code snippet, you set up 2 variables, then did math on them but did not store the result. Your code -
Code: Select all
put the width of this stack into width1
put the height of this stack into height1
divide width1 by 2 -- this is divided, but not stored...
divide height1 by 2 -- this is divided, but not stored...
You also had :
set the center of image "Icon.png" to
width1
Width 1 would be the width of the stack for the reason noted above, and so only 1 coordinate, so even if 'the center' was a property, you would have given it incomplete information for it to actually work.
Jean-Marc's example stored the result back into width1 and width2.
Lastly, I would point out that you really don't need to go through all of that to center an image if your using 'loc', this would work just as well -
<I am assuming your dialog box is a custom one you made up, but that shouldn't matter. I made a stack with 2 buttons, and an image, and used this for the code >
Code: Select all
# button "Center"
on mouseUp
set the loc of image "info" to the loc of this card
--I used "this card" because for this example, there is only 1 stack and card,
-- however, you could just as easily use the name or long id of the card...
end mouseUp
# button "Reset"
on mouseUp
set the loc of image "info" to 20,20
end mouseUp
And here is the stack -
- centerMe.zip
- A centering example...
- (1.1 KiB) Downloaded 171 times