PDA

View Full Version : [AS3] button component and HTML


sicopatico
02-11-2012, 10:08 PM
Hi all - Thanks to all those answers to other peoples posts this is the first time in a year that I have had to actually ask a question.. so without further ado *lurk mode off* =P

Ok so I am making a fun little flash text-based free-for-all arena type game.
Now I can use HTML for my textfield just fine and I like the ease of using html tags as it doesnt change the style of the textfield (ie bold, color, etc) except between the tags.
Basically I wanted to add some color so now damage is colored red and names are colored pink or blue depending on sex of the opponent (name/stats/gender of each in their own array which is added to another array which presto makes an easy multidimensional array for a nice searchable list). Either way doing the changes in the text field was easy.

Anyways my buttons(1-12) on the stage appear/disappear and change depending on what you use for instance if button1 is clicked on it would change the 12 buttons labels to the opponents that are currently occupying the same room (or hide the ones that arent used). Now Since I wanted to add color i thought i would add the html code to the buttonlabel changing the htmlcode color for the listed name depending on the gender though apparently it only accepts plain text x.x

Now my dilemma - i know of a way to change the button label depending on which gender though its a big run around (since when you use the setstyle it changes any new label change for that button to the same style thus if i had a male gender name change it to blue than the person hit cancel going back to the mainscreen (thus giving the fight options again) that fight label for button 1 would still be blue meaning i would have to create either separate functions for my buttonwriting function or create new buttons all together with dynamic textboxes imbedded into them (so a tutorial on this somewhere)

now the reason i like HTML tags is that when i change the color its only for that particular section of writing and reverts back to the original style after you close the tag. Is there any way to do this for button labels (ie only changing the style/color for that label change) without making either 'several different'/'single complex' function(s)?

here is an example of the colorname function which changes my textfield and what i mean

public function combat(m:Array, m1:array)//i shortened this code for this example removing all stat and combat related stuff since you really dont need that
{
txt(m,cname(m)+" Hits "+cname(m1)+" for "+Dmg(dmg), false)
}
public function cname(m:Array)
{
var t:String
if(m[11]==0)//female
t="<font color='#FF33CC'>"+m[1]+"</font>"
if(m[11]==1)//male
t="<font color='#3366FF'>"+m[1]+"</font>"
return t
}
//and just for fun my txt function
public function outputmaintext(m:Array,e:String,e1:Boolean)
{
if(m[3]==player[3])
{
if (e1 == false)
currenttext = currenttext + "\n" + e;
}
if(e1 == true)
currenttext = e;
if(currenttext.length>10000)
{
var t:String = currenttext.slice(5000,currenttext.length)
currenttext=t
}
maintextbox.htmlText = currenttext
if(maintextbox.numLines > 21)
maintextbox.scrollV = maintextbox.numLines - 21
return;
}// end function