I'm using a DialogBoxMorph in Squeak, and need help sending parameters to a button action.
Currently, I have this:
tempBtn _ self buttonLabel: tempStr
action: #doSomething.How do I make it send a parameter to doSomething when it's clicked?
Offline
nXIII wrote:
Just look at DialogBoxMorph >> withButtonsForYes:no:okay:cancel:
buttonRow addMorphBack: (self buttonLabel: 'Yes' localized action: #yes)
That doesn't really seem to help me find a way to fire a function with a parameter when a button is clicked.
Let me give more detailed code:
initialize
| t1 t2 t3 t4 t5 t6 |
super initialize.
self title: 'Latest Projects on Mod Share'.
t1 _ self buttonLabel: 'Close' action: #delete.
t2 _ (HTTPSocket httpGet: 'http://modshare.tk/api/getallprojectsinfo/insanity') contents.
(t2 findString: 'banned')
> 0
ifTrue:
[DialogBoxMorph inform: 'You are banned from Mod Share and can''t browse it.' title: 'Failed'.
^ self].
t4 _ t2 findTokens: '|'.
t4 do:
[:t7 |
t5 _ t7 findTokens: ':'.
t6 _ self buttonLabel: (t5 at: 2)
action: 'self downloadProject:' , (t5 at: 1).
t6 extent: 200 @ 35.
mainColumn addMorph: t6].
buttonRow addMorph: t1I need the action to fire downloadProject with the parameter shown (element 1 of t5).
Offline
jvvg wrote:
That doesn't really seem to help me find a way to fire a function with a parameter when a button is clicked.
![]()
…
I need the action to fire downloadProject with the parameter shown (element 1 of t5).
That's not how selectors work.
EDIT: Also, name your instance variables with descriptive names. It's bad practice to use decompiled-code-style ones.
Last edited by nXIII (2012-10-17 19:46:42)
Offline
nXIII wrote:
jvvg wrote:
That doesn't really seem to help me find a way to fire a function with a parameter when a button is clicked.
![]()
…
I need the action to fire downloadProject with the parameter shown (element 1 of t5).That's not how selectors work.
EDIT: Also, name your instance variables with descriptive names. It's bad practice to use decompiled-code-style ones.
Hmm... that's a problem. Do you know any way around that?
They used to have descriptive names, but Squeak changed them on me.
Offline