Array of Objects

Monkey Forums/Monkey Programming/Array of Objects

c.k.(Posted 2011) [#1]
I want to create an array of buttons:

Local bttns:ArrayList<MyButton>


Is that the way to do it? I'm creating a button like

newBttn = New MyButton
'...
bttns.AddLast( newBttn )


but that doesn't seem to work. So how do I make an array of objects I can then reference with something like

bttns[x].Enabled = true
'or
bttns[x].soundClick.Play()



xzess(Posted 2011) [#2]
I'm not sure, but i use lists and stacks this way

global bttns:List<MyButton>


newBttn = New MyButton
...
bttns.AddLast(newBttn)


Function GetButtonByID(id:Int)
Local IDcounter:Int=0
	For Local b:myButton = eachin bttns
		If(IDcounter = id)
		Return b
		Else
		IDcounter += 1
		End
	Next
End

local b:myButton = GetButtonByID[x]
b.Enabled = true
'or
b.soundClick.Play()


Same with stacks.

Greetz


Samah(Posted 2011) [#3]
c.k.:
What's the exact problem you're having? Is it a compile error? Are you actually instantiating the ArrayList?


c.k.(Posted 2011) [#4]
At first I had failed to instantiate the object. That prompted my post. However, after having fixed that, I'm having issues calling the methods of a Super's Super. :)

I'm slowly working things out in my brain. I've never really programmed in an OOP before, but I'll get it here shortly. I hope. :)


Samah(Posted 2011) [#5]
Code sample! :)


TheRedFox(Posted 2011) [#6]
With only arrays, I was able to do this:

Global Areas:Area[] = [New Area(MAINMENU_AREAS, "intro", 10,156,245,210),
                New Area(MAINMENU_AREAS, "nombres", 100,213,339,258),
				New Area(MAINMENU_AREAS, "comprehension", 211,261,415,307),
				New Area(MAINMENU_AREAS, "memorisation", 341,311,587,357)]



Area is a class.