- Home /
Passing Texture Names from Array to Buttons
Hello, I have been working on writing a script that will allow me to store all of the names of buttons in an array. With code like this.
var spellTextureArray:Array = new Array( spellTexture0, spellTexture1, spellTexture2, spellTexture3);
Then I try and do a for loop to iterate through the creation of the buttons like this.
for(var j:int = 0; j < spellArray.length; j++)
{
if (spellArray[j].Contains(Event.current.mousePosition))
{
if (GUI.RepeatButton(Rect(spellArray[j]), spellTextureArray[j]) && mdown == false)
{
mdown = true;
//print("spell " + j + " mouse is down");
}
else
{
mdown = false;
//print("spell " + j + " mouse is up");
}
}
else
{
GUI.RepeatButton(Rect(spellArray[j]), spellTextureArray[j]);
}
}
The textures names are not passing to the GUI.RepeatButton operation. I can hard code the name and the texture shows up, so I know the texture is linked. Is there something obvious that I am missing? This has me pretty stumped.
Best Regards,
Steve
Answer by Yanger_xy · Jun 21, 2011 at 03:06 PM
Check your spellTextureArray. Are you sure that its elements are validating?
Thanks Yanger,
You're right, it's not accepting the values into the array. Of course if I change them to strings, it does, but then the buttons print the name of the texture as text, and not the desired result of linking the textures to the buttons.
So it looks like the root of the trouble is in the array code, and not the button code. Have any ideas of how to store a name of a texture in an array? Or to convert the string into a command in the button code?
Thanks for your help on this! $$anonymous$$uch appreciated.
Steve
Sweet! I figured it out. After assigning the strings to the array, I reassigned them as the name and kapow! it worked. Thanks Yanger!
Your answer
Follow this Question
Related Questions
Null Reference Exception After refering to an Array 1 Answer
Array of buttons not displaying in game 1 Answer
Link image sequence to an array 2 Answers
Array based floor 3D game flat plane 1 Answer