Re: [Newbies] SimpleSliderMorph target setting question.
Thanks to all who replied to my SimpleSliderMorph question. I was trying to set the target with the the inspector window as a quick way to test my program. Got things working now, thanks! Tim ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Re: [Newbies] SimpleSliderMorph target setting question.
On Friday 21 Nov 2008 7:04:21 am Tim Patti wrote: > The above code works in the workspace and transcript, but I cannot figure > out how to point the SimpleSliderMorph target to my instance si. Tried all > kind of combinations with no luck Turn on "create textual references to dropped morphs" in workspace titlebar menu and drop the morph into the workspace to paste a text reference. HTH .. Subbu ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
[Newbies] SimpleSliderMorph target setting question.
Assuming you have a simple class SecondaryCoil Object subclass: #SecondaryCoil instanceVariableNames: 'turns' classVariableNames: '' poolDictionaries: '' category: 'MyApp' with an instance variable "turns" and an accessor methods #turns to get the value: turns "Returns the turns value" ^turns and another method #turns: to set the value of the instance variable: turns: aNumber "Sets the turns value" turns := aNumber then you can use: |slider coil| slider := SimpleSliderMorph new. coil := SecondaryCoil new. slider target: coil. slider actionSelector: #turns:. slider openInWorld. coil inspect which is easier to write using "method chaining" as |slider coil| slider := SimpleSliderMorph new. coil := SecondaryCoil new. slider target: coil; actionSelector: #turns:; openInWorld. coil inspect Click on the instance variable in the inspector of your coil instance and change the slider. The value gets updated. What's the idea: a slider acts on a target and you tell him to send a message with the given selector name to this target anytime its own value changes. Since the slider will give the sliders value as an argument to the target the selector has to be a method accepting one argument. By default the slider uses values from 0.0 to 1.0 but you can change this if required: |slider coil| slider := SimpleSliderMorph new. coil := SecondaryCoil new. slider target: coil; actionSelector: #turns:; minVal: 0; maxVal: 360; openInWorld. coil inspect You can also provide another method on your new class and use #reportTurns: as action selector: reportTurns: aNumber "Sets the given turns and reports the value" self turns: aNumber. Transcript show: self turns asString. Since your new object is referenced by the inspector window and the slider (who holds it in an instance variable "target") it will not "die" instantly. If you close both of them and your new object instance is not referenced elsewhere it get collected when the garbage collector run. BTW: Note that in Smalltalk you typically use just "turns:" as the methods name for accessors. (setTurns: is more Java style) If you use the Refactoring browser or the OmniBrowser (included in Damiens dev images) you can select an instance variable name (in the class creation expression above) and use the context menu to automatically create the accessor methods for you. Have fun Torsten http://astares.blogspot.com -- Sensationsangebot nur bis 30.11: GMX FreeDSL - Telefonanschluss + DSL für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
[Newbies] SimpleSliderMorph target setting question.
Hi all, I've been stuck for a couple of days on trying to figure out how to properly set the target and setValueSelector of a SimpleSliderMorph. My intended target is an instance of a class that I created in the workspace and I assume the setValueSelector is what I use to send the value to a method in my instance of the class. si := SecondaryCoil. "make an instance of the class" si setTurns:10."set the turns to 10" Transcript show:getTurns."print the turns" The above code works in the workspace and transcript, but I cannot figure out how to point the SimpleSliderMorph target to my instance si. Tried all kind of combinations with no luck. I'd like to be able to use the slider to set the turns of the coil in my instance of SecondaryCoil. I have 4 books on Squeak but I must me missing something obvious here. Tim ___ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners