Array of Objects
Monkey Forums/Monkey Programming/Array of Objects
| ||
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() |
| ||
I'm not sure, but i use lists and stacks this wayglobal 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 |
| ||
c.k.: What's the exact problem you're having? Is it a compile error? Are you actually instantiating the ArrayList? |
| ||
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. :) |
| ||
Code sample! :) |
| ||
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. |